

var $a = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

var CurrentStyle = function(element){
	return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}

var Bind = function(object, fun) {
	var args = Array.prototype.slice.call(arguments).slice(2);
	return function() {
		return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
	}
}

var Tween = {
	Quart: {
		easeOut: function(t,b,c,d){
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		}
	},
	Back: {
		easeOut: function(t,b,c,d,s){
			if (s == undefined) s = 1.70158;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		}
	},
	Bounce: {
		easeOut: function(t,b,c,d){
			if ((t/=d) < (1/2.75)) {
				return c*(7.5625*t*t) + b;
			} else if (t < (2/2.75)) {
				return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
			} else if (t < (2.5/2.75)) {
				return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
			} else {
				return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
			}
		}
	}
}


//容器对象,滑动对象,切换数量
var SlideTrans = function(container, slider, count, options) {
	this._slider = $a(slider);
	this._container = $a(container);//容器对象
	this._timer = null;//定时器
	this._count = Math.abs(count);//切换数量
	this._target = 0;//目标值
	this._t = this._b = this._c = 0;//tween参数
	
	this.Index = 0;//当前索引
	
	this.SetOptions(options);
	
	this.Auto = !!this.options.Auto;
	this.Duration = Math.abs(this.options.Duration);
	this.Time = Math.abs(this.options.Time);
	this.Pause = Math.abs(this.options.Pause);
	this.Tween = this.options.Tween;
	this.onStart = this.options.onStart;
	this.onFinish = this.options.onFinish;
	
	var bVertical = !!this.options.Vertical;
	this._css = bVertical ? "top" : "left";//方向
	
	//样式设置
	var p = CurrentStyle(this._container).position;
	p == "relative" || p == "absolute" || (this._container.style.position = "relative");
	this._container.style.overflow = "hidden";
	this._slider.style.position = "absolute";
	
	this.Change = this.options.Change ? this.options.Change :
		this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count;
};
SlideTrans.prototype = {
  //设置默认属性
  SetOptions: function(options) {
	this.options = {//默认值
		Vertical:	true,//是否垂直方向（方向不能改）
		Auto:		true,//是否自动
		Change:		0,//改变量
		Duration:	50,//滑动持续时间
		Time:		10,//滑动延时
		Pause:		2000,//停顿时间(Auto为true时有效)
		onStart:	function(){},//开始转换时执行
		onFinish:	function(){},//完成转换时执行
		Tween:		Tween.Quart.easeOut//tween算子
	};
	Extend(this.options, options || {});
  },
  //开始切换
  Run: function(index) {
	//修正index
	index == undefined && (index = this.Index);
	index < 0 && (index = this._count - 1) || index >= this._count && (index = 0);
	//设置参数
	this._target = -Math.abs(this.Change) * (this.Index = index);
	this._t = 0;
	this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]);
	this._c = this._target - this._b;
	
	this.onStart();
	this.Move();
  },
  //移动
  Move: function() {
	clearTimeout(this._timer);
	//未到达目标继续移动否则进行下一次滑动
	if (this._c && this._t < this.Duration) {
		this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));
		this._timer = setTimeout(Bind(this, this.Move), this.Time);
	}else{
		this.MoveTo(this._target);
		this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause));
	}
  },
  //移动到
  MoveTo: function(i) {
	this._slider.style[this._css] = i + "px";
  },
  //下一个
  Next: function() {
	this.Run(++this.Index);
  },
  //上一个
  Previous: function() {
	this.Run(--this.Index);
  },
  //停止
  Stop: function() {
	clearTimeout(this._timer); this.MoveTo(this._target);
  }
};

function showLoginCover(){
	var cover = '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'+
			    '    <div class="modal-dialog">'+
			    '        <div class="modal-content">'+
						    '<div class="ch-container modal-body">' + 
							'    <div class="">' + 
							'	    <div class="">' + 
							'	        <div class="col-md-12 center login-header" style="float:none;">' + 
							'	            <h2>欢迎来到国开</h2>' + 
							'	        </div>' + 
							'	    </div>' + 
							'	    <div class="">' + 
							'	        <div class="well center login-box">' + 
							'	            <div class="alert alert-info">请输入您的用户名和密码</div>' + 
							'	            <div class="input-group input-group-lg">' + 
							'	                <span class="input-group-addon"><i class="glyphicon glyphicon-user red"></i></span>' + 
							'	                <input id="unm" type="text" class="form-control" placeholder="Username">' + 
							'	            </div>' + 
							'	            <div class="clearfix"></div><br>' + 
							'	            <div class="input-group input-group-lg">' + 
							'	                <span class="input-group-addon"><i class="glyphicon glyphicon-lock red"></i></span>' + 
							'	                <input id="pwd" type="password" class="form-control" placeholder="Password">' + 
							'	            </div>' + 
							'	            <div class="clearfix"></div>' + 
							'	            <div class="input-prepend" style="margin-top:20px;">' + 
							'	                <label class="remember" for="remember"><input type="checkbox" id="remember"> Remember me</label>' + 
							'	            </div>' + 
							'	            <div class="clearfix"></div>' + 
							'	        </div>' + 
							'	    </div>' + 
							'	</div>' + 
							'</div>' + 
			    '            <div class="modal-footer" style="text-align:center;">'+
			    '                <a href="#" id="fucBtn" class="btn btn-primary" data-dismiss="modal" onclick="Signup.lgn();">登陆</a>'+
			    '                <a href="#" class="btn btn-default" data-dismiss="modal">取消</a>' + 
			    '            </div>'+
			    '        </div>'+
			    '    </div>'+
			    '</div>';

	$("#cover").html(cover);
    $('#myModal').modal('show');			
}

var IndexStudent = {
	/* 定金课程常量 2017年6月9日11:08:44 G */
	CONST_COUR_NAME:'新媒体数字营销传播项目培训预付款',
	scollImgLeft: function(){
		var speed=20;
		marquePic2.innerHTML=marquePic1.innerHTML;
		function Marquee(){ 
			if(teacherList.scrollLeft>=marquePic1.scrollWidth)
				teacherList.scrollLeft=0;
			else 
				teacherList.scrollLeft++;
		} 
		var MyMar=setInterval(Marquee,speed);
		teacherList.onmouseover=function(){clearInterval(MyMar);} 
		teacherList.onmouseout=function(){MyMar=setInterval(Marquee,speed);} 
	},
	listHomeInit: function(){
		var saveUser = GetLS("saveUser");
		if (saveUser){
			$("#unm").val(saveUser.email);
			$("#pwd").val(saveUser.password);
		}
		$ajax({
			url:"/listHome",
			data:{
				count : 6
			},
			success: function(res) {
				var data = res.result;
				var certificate = "";
				//首页免费体验区
				var coursesFree = "";
				var coursesFreeA = "";
				// for (var i = 0; i < data.coursesFree.length-5; i ++){
				// 	var img = "img/t1.png";
				// 	if (data.coursesFree[i].photo){
				// 		img = Core.id2url(data.coursesFree[i].photo);
				// 	}
				// 	coursesFreeA += '<div class="courBox fl gkCour mycoursesFreeSin" data-id="' + data.coursesFree[i]._id + '">'+
				// 					'	<dl>'+
				// 					'		<dt><img src="img/freeA.jpg"></dt>'+
				// 					'		<dd class="fs16 ellipsis"><a href="">' + data.coursesFree[i].name + '</a></dd>'+
				// 					'		<dd class="fs14 c9 ellipsis">' + data.coursesFree[i].des + '</dd>'+
				// 					'	</dl>'+
				// 					'</div>';
				// }
				coursesFreeA += '<div class="courBox fl gkCour mycoursesFreeSin" data-id="5642d70c665517c95cb8ddb1">'+
									'	<dl>'+
									'		<dt><img src="img/freeA.jpg"></dt>'+
									'		<dd class="fs16 ellipsis"><a href="">幼儿学习故事公开课</a></dd>'+
									'		<dd class="fs14 c9 ellipsis">本门课程从新西兰幼儿学习故事的理念与实践的介绍出发</dd>'+
									'	</dl>'+
									'</div>';
				for (var i = 1; i < data.coursesFree.length-1; i ++){
					// coursesFree += '<div class="threeList">';
					// for (var j = 0; j < 3; j ++){
					// 	if (!data.coursesFree[i*3+j])
					// 		continue;
					// 	var img = "img/t1.png";
					// 	if (data.coursesFree[i*3+j].photo)
					// 		img = Core.id2url(data.coursesFree[i*3+j].photo);
					// 	var teacherName = '';
					// 	if (data.coursesFree[i*3+j].teachers[0])
					// 		teacherName = data.coursesFree[i*3+j].teachers[0].name;
					// 	coursesFree +=  '<div class="singleC mycoursesFreeSin" data-id="' + data.coursesFree[i*3+j]._id + '">' + 
					// 					'	<img src="' + img + '" style="width:100%;height:223px;">' + 
					// 					'	<div class="ut-s" style="font-size:16px;font-weight:bold;padding-top:10px;">' + data.coursesFree[i*3+j].name + '</div>' + 
					// 					'	<div class="ut-s" style="font-size:12px;border-bottom:1px solid #e5e5e5;color:#888888;padding-top: 0;height:30px;">' + data.coursesFree[i*3+j].des + '</div>' + 
					// 					'</div>';
					// 	if (j != 3)
					// 		coursesFree += '<div class="wh"></div>';						
					// }				
					// coursesFree += '</div>';

					var img = "img/t1.png";
					if (data.coursesFree[i].photo){
						img = Core.id2url(data.coursesFree[i].photo);
					}
					coursesFree += '<div class="courBox fl mycoursesFreeSin" data-id="' + data.coursesFree[i]._id + '">'+
									'	<dl>'+
									'		<dt><img src="' + img + '"></dt>'+
									'		<dd class="fs16 ellipsis"><a href="">' + data.coursesFree[i].name + '</a></dd>'+
									'		<dd class="fs14 c9 ellipsis">' + data.coursesFree[i].des + '</dd>'+	
									'	</dl>'+
									'</div>';
				}
				
				$("#coursesFreeListIndex").html(coursesFree);
				$("#gkCour").html(coursesFreeA);

				$(".mycoursesFreeSin").click(function(){
					window.location.href = "a_freeVideo.html?stype=coursefree&id=" + $(this).data("id");
				});
				$("#moreCourseFree").click(function(){
					// window.location.href = "a_indexMoreList.html?stype=coursefree";
				});
				// add
				
				//首页证书 修改
				// console.log(data.certificates)
				var certifiArray = ['5552b7d3b0b0e9bd66fc6d2c','5552bae0b0b0e9bd66fc6d2d','550a90e96870af4e1c113b4d','550a941e6870af4e1c113b4f','550a6462dd5c26c3175efd4b'];
				for(var i=0;i<data.certificates.length; i ++){
					var certipay = true;
					var img = "img/t2.png";
					if (data.certificates[i].photo){
						img = Core.id2url(data.certificates[i].photo);
					}
					var certipay = true;
					if(certifiArray.indexOf(data.certificates[i]._id) != -1)
						certipay = false;
					certificate += '<div class="courBox fl zsList myCertSin" data-id="'+data.certificates[i]._id + '" data-certipay="'+certipay + '">'+
									'	<dl>'+
									'		<dt><img src="'+ img +'"></dt>'+
									'		<dd class="fs16 ellipsis"><a>' + data.certificates[i].name +'</a></dd>'+
									'		<dd class="fs14 c9 ellipsis">' + data.certificates[i].des +'</dd>'+
									'		<dd style="border-top:1px solid #EBEBEB;height:0"></dd>'+
									'		<dd class="fs14 c9 ellipsis">颁证机构：' + data.certificates[i].organization + '</dd>'+
									'	</dl>'+
									'</div>';
				}
				$("#certificateListIndex").html(certificate);
				// 点击跳转
				$(".myCertSin").click(function(){
					window.location.href = "a_indexDetailCertificate.html?stype=certificate&id=" + $(this).data("id")+'&certipay='+$(this).data("certipay");
				});

				//首页课程 修改
				var coursea = "";
				var courseb = "";
				var coursec = "";
				var coursed = "";
				var k=0;
				var l=0;
				var z=0;
				var x=0;
				$ajax({
					url:"/course/listCourseShouYe",  //2019-4-3
					data:{
						status: 3,
						ctype: ["550252e7179e54560dfab8e7", "550252fb179e54560dfab8e8", "5653d0f8823f92f932d15881", "562f1f3b99bf91651845f1f8"]
					},
					success:function(res){
						
						for(var i=0;i<res.result.length;i++){
							
							var img = "img/t3.png";
							if (res.result[i].photo){
								img = Core.id2url(res.result[i].photo);
							}
							
							var teacherName = '';
							var teacherPhoto = '';
							if (res.result[i].teachers[0]){
								teacherName = res.result[i].teachers[0].name;
								teacherPhoto = Core.id2url(res.result[i].teachers[0].photo);
							}	
							var credit = '';
							if (res.result[i].credit){
								credit = res.result[i].credit;
							}
							if(res.result[i].fee != 0){
								if(res.result[i].ctype == "550252e7179e54560dfab8e7"){
									k += 1;
									if(k <= 2){
										coursea += '<div class="courBox fl hotCour myCourseSin" style="margin-top:10px" data-id="' + res.result[i]._id + '">'+
													'	<dl>'+
													'		<dt><img src="'+img+'"></dt>'+
													'		<dd class="fs16 ellipsis"><a >'+res.result[i].name+'</a></dd>'+
													'		<dd class="fs14 c9 ellipsis">'+res.result[i].des+'</dd>'+
													'		<dd style="border-top:1px solid #EBEBEB;height:0"></dd>'+
													'		<dd class="fs12 c9">'+
													'			<span class="fl ellipsis" style="width:164px;"><i><img src="'+teacherPhoto+'"></i>授课老师：'+teacherName+'</span>'+
													'			<span class="fr">认证学分：'+credit+'分</span>'+
													'		</dd>'+
													'	</dl>'+
													'</div>';
									}
								}
								if(res.result[i].ctype == "550252fb179e54560dfab8e8"){
									l += 1;
									if(l <= 2){
									courseb += '<div class="courBox fl hotCour myCourseSin" style="margin-top:10px" data-id="' + res.result[i]._id + '">'+
												'	<dl>'+
												'		<dt><img src="'+img+'"></dt>'+
												'		<dd class="fs16 ellipsis"><a >'+res.result[i].name+'</a></dd>'+
												'		<dd class="fs14 c9 ellipsis">'+res.result[i].des+'</dd>'+
												'		<dd style="border-top:1px solid #EBEBEB;height:0"></dd>'+
												'		<dd class="fs12 c9">'+
												'			<span class="fl ellipsis" style="width:164px;"><i><img src="'+teacherPhoto+'"></i>授课老师：'+teacherName+'</span>'+
												'			<span class="fr">认证学分：'+credit+'分</span>'+
												'		</dd>'+
												'	</dl>'+
												'</div>';
									}
								}
								if(res.result[i].ctype == "5653d0f8823f92f932d15881"){
									z += 1;
									if(z <= 2){
									coursec += '<div class="courBox fl hotCour myCourseSin" style="margin-top:10px" data-id="' + res.result[i]._id + '">'+
												'	<dl>'+
												'		<dt><img src="'+img+'"></dt>'+
												'		<dd class="fs16 ellipsis"><a >'+res.result[i].name+'</a></dd>'+
												'		<dd class="fs14 c9 ellipsis">'+res.result[i].des+'</dd>'+
												'		<dd style="border-top:1px solid #EBEBEB;height:0"></dd>'+
												'		<dd class="fs12 c9">'+
												'			<span class="fl ellipsis" style="width:164px;"><i><img src="'+teacherPhoto+'"></i>授课老师：'+teacherName+'</span>'+
												'			<span class="fr">认证学分：'+credit+'分</span>'+
												'		</dd>'+
												'	</dl>'+
												'</div>';
									}
								}
								if(res.result[i].ctype == "562f1f3b99bf91651845f1f8"){
									x += 1;
									if(x <= 2){
									coursed += '<div class="courBox fl hotCour myCourseSin" style="margin-top:10px" data-id="' + res.result[i]._id + '">'+
												'	<dl>'+
												'		<dt><img src="'+img+'"></dt>'+
												'		<dd class="fs16 ellipsis"><a>'+res.result[i].name+'</a></dd>'+
												'		<dd class="fs14 c9 ellipsis">'+res.result[i].des+'</dd>'+
												'		<dd style="border-top:1px solid #EBEBEB;height:0"></dd>'+
												'		<dd class="fs12 c9">'+
												'			<span class="fl ellipsis" style="width:164px;"><i><img src="'+teacherPhoto+'"></i>授课老师：'+teacherName+'</span>'+
												'			<span class="fr">认证学分：'+credit+'分</span>'+
												'		</dd>'+
												'	</dl>'+
												'</div>';
									}
								}
											
							}
						}
						$("#courA").html(coursea);
						$("#courB").html(courseb);
						$("#courC").html(coursec);
						$("#courD").html(coursed);

						$(".myCourseSin").click(function(){
							window.location.href = "a_indexDetailCourseFirst.html?stype=course&id=" + $(this).data("id");
						});
					}
				});

			//  首页讲师
			// 	var teachers =  '<div id="teacherList" style="overflow:hidden;">' + 
			// 					'<table border="0" align="center" cellpadding="0" cellspacing="0">' + 
			// 					'	<tr>' + 
			// 					'		<td id="marquePic1">' + 
			// 					'			<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">' + 
			// 					'				<tr>';
			// 	for (var i = 0; i < data.teachers.length; i ++){
			// 		var img = "img/t2.png";
			// 		if (data.teachers[i].photo)
			// 			img = Core.id2url(data.teachers[i].photo);
			// 		teachers += '<td class="teacherSin" align="center" data-id="' + data.teachers[i]._id + '">' + 
			// 					'	<img src="' + img + '"><br><br>' + 
			// 					'	<span>' + data.teachers[i].name + '</span>' + 
			// 					'</td>';
			// 	}
			// 	teachers += '</tr>' + 
			// 			'</table>' + 
			// 		'</td>' + 
			// 		'<td id="marquePic2"></td>' + 
			// 	'</tr>' + 
			// '</table>' + 
			// '</div>';
			// 	$("#idContainer3").html(teachers);
			// 	IndexStudent.scollImgLeft();
			// 	$(".teacherSin").click(function(){
			// 		window.location.href = "a_indexDetailTeacher.html?stype=teacher&id=" + $(this).data("id");
			// 	});
			// 	$("#moreTeacher").click(function(){
			// 		window.location.href = "a_indexMoreList.html?stype=teacher";
			// 	});
			}
		});
	},
	showLogin: function(){
		// showCover('提示信息','请添加类型名称','','','');
		showLoginCover();
	},
	jump: function(){
		var CurrentUser = GetLS("user");
		if (CurrentUser && CurrentUser.utype != UTYPE.VISITOR) {
			if (CurrentUser.utype == UTYPE.STUDENT) 
				window.location.href = "a_indexStudy.html?" + random() + "#myCourseList";
			else
				window.location.href = "admin.html";
		}	
	},
	moreListInit: function(){
		var stype = $.query.get("stype");
		var ctype = $.query.get("ctypeid");
		//所有证书
		if (stype == "certificate") {
			$("#bannerImg").css('background-image', 'url("../img/bufa.jpg")');
			$("#bannerImg").css('height', '330px');
			$("#bannerImg").css('background-position', 'center center');
			$("#course-list").text("证书分类：");
			$("#allNameText").text("全部证书");
			$ajax({
				url: "/certificateType/list",
				data:{},
				success: function(res) {
					var html = "";
					for (var i = 0; i < res.result.length; i ++){
						html += '<li class="ctypeEvt" id="'+res.result[i]._id+'" data-id="'+res.result[i]._id+'">' +res.result[i].name+ '</li>';
					}
					$("#ctype").append(html);
					$(".ctypeEvt").click(function(){
						$(".ctypeEvt").removeClass("active_n");
						$(this).addClass("active_n");
						listFn($(this).data("id"));
					});
					if (ctype){
						$("#" + ctype).click();
					}
				}
			});
			var listFn = function(ctype){
				$ajax({
					url:"/certificate/listFirstPage",
					data:{
						status: STATUS.SHELVES,
						ctype: ctype
					},
					success: function(res) {
						var data = res.result;			
						$("#listName").text("所有证书");
						var certificate = "";
						for (var i = 0; i < data.length; i ++){
							var certipay = true;
							var img = "img/t2.png";
							var certipay = true;
							if (data[i].photo){
								img = Core.id2url(data[i].photo);
							}
							if(noBuyCertificati.indexOf(data[i]._id) != -1)
								certipay = false;
							certificate +=  '<div class="box_n addcour myCertSin" data-id="'+data[i]._id+'" data-certipay="'+certipay+'">'+
											'	<dl>'+
											'		<dt><img src="'+img+'"></dt>'+
											'		<dd class="fs16 ellipsis">' + data[i].name + '</dd>'+
											'		<dd class="c80 ellipsis" style="border-bottom: 1px solid #E6E6E6;">' + data[i].des + '</dd>'+
											'		<div class="addshouke" style="height:40px;line-height:40px;">'+
											'			<p class="fl">颁证机构： ' + data[i].organization + '</p>'+
											'		</div>'+
											'	</dl>'+
											'</div>';

							if(i != 0 && (i+1)%4 == 0){
								certificate += '<div class="bor_n"></div>'
							}
						}

						$("#moreList").html(certificate);
						$(".myCertSin").click(function(){
							var ctypeName = $("#ctype").find(".active_n").text();
							window.location.href = "a_indexDetailCertificate.html?stype=certificate&id=" + $(this).data("id") + "&ctypeName=" + ctypeName+"&certipay="+$(this).data("certipay");
						});
					}
				});		
			}
			if (ctype){
				listFn(ctype);
			}
			else{
				listFn();
			}
		} 
		//所有课程
		else if (stype == "course"){	
			$("#bannerImg").css('background-image', 'url("../img/xuexi.jpg")');
			$("#bannerImg").css('height', '330px');
			$("#bannerImg").css('background-position', 'center center');
			$("#allNameText").text("全部课程");
			$ajax({
				url: "/certificateType/list",
				data:{},
				success: function(res) {
					var html = "";
					for (var i = 0; i < res.result.length; i ++){
						// html += '<div class=" ctypeEvt" id="' + res.result[i]._id + '" data-id="' + res.result[i]._id + '">' + 
						// 		'	<div class="iconImg"> '+
						// 		//'<img src="img/head_icon2.png" style="width:2em;">'+ 注掉课程分类图像
						// 		'</div>' + 
						// 		'	<div class="uma5 ut-s" style="width:4.4em;">'  + res.result[i].name + '</div>' + 
						// 		'	<span class="more "></span>' + 
						// 		'</div>';
						html += '<li class="ctypeEvt" id="'+res.result[i]._id+'" data-id="'+res.result[i]._id+'">' +res.result[i].name+ '</li>';
					}
					$("#ctype").append(html);
					$(".ctypeEvt").click(function(){
						$(".ctypeEvt").removeClass("active_n");
						$(this).addClass("active_n");
						listFn($(this).data("id"));
					});
					if (ctype){
						$("#" + ctype).click();
					};

				}
			});
			var listFn = function(ctype){
				$ajax({
					url: "/course/listCourseShouYe", //2019-4-7
					data:{
						status: 3,
						ctype: ctype
					},
					success: function(res) {
						var data = res.result;
						var course = "";
						for (var i = data.length-1; i >= 0; i --){
							if (data[i].fee == "0")
								data.splice(i,1);
						}
						for (var i = 0; i < data.length; i ++){
							var img = "img/t3.png";
							if (data[i].photo)
								img = Core.id2url(data[i].photo);
							var teacherName = '';
							var teacherPhoto = 'img/tou2.jpg';
							if (data[i].teachers[0]){
								teacherName = data[i].teachers[0].name;
								teacherPhoto = Core.id2url(data[i].teachers[0].photo);
							}	
							var credit = '';
							if (data[i].credit)
								credit = data[i].credit;

							course +=  '<div class="box_n addcour myCourseSin" data-id="'+data[i]._id+'">'+
											'	<dl>'+
											'		<dt><img src="'+ img +'"></dt>'+
											'		<dd class="fs16 ellipsis">'+data[i].name+'</dd>'+
											'		<dd class="c80 ellipsis" style="border-bottom: 1px solid #E6E6E6;">'+ data[i].des +'</dd>'+
											'		<div class="addshouke">'+
											'			<span style="width:40px;padding:0"><img src="'+ teacherPhoto +'"></span>'+
											'			<span style="padding-right:15px">授课老师：'+ teacherName +'</span>'+
											'			<span style="padding:0">认证学分：'+ credit +'学分</span>'+
											'		</div>'+
											'	</dl>'+
											'</div>';

							if(i != 0 && (i+1)%4 == 0){
								course += '<div class="bor_n"></div>'
							}
						}
						$("#moreList").html(course);
						$(".myCourseSin").click(function(){
							var id = $(this).data("id");
							if(id == '59c344fae6d7da5458d9cd5a'){//生殖健康 特殊处理
								locaHref("reprHeal.html?id="+id);
							}else
								window.location.href = "a_indexDetailCourseFirst.html?stype=course&id=" + $(this).data("id");
						});

						// Pagingadd
						// var items = res.result;
						// var courlengh = items.length;
						// var pageall = courlengh/16;
						// if(courlengh%16 != 0){
						// 	pageall +=1;
						// }
						// console.log(pageall);
					}
				});
			}
			if (ctype)
				listFn(ctype);
			else
				listFn();
		}
		//所有免费课程
		else if (stype == "coursefree") {
			// $("#bannerImg").css('background-image', 'url("../img/xuexi.jpg")');
			// $("#bannerImg").css('height', '300px');
			// $("#bannerImg").css('background-position', 'center center');
			$("#courAll").hide();
			$("#courFree").show();
			$ajax({
				url: "/certificateType/list",
				data:{},
				success: function(res) {
					var html = "";
					for (var i = 0; i < res.result.length; i ++){
						// html += '<div class=" ctypeEvt" data-id="' + res.result[i]._id + '">' + 
						// 		'	<div class="iconImg"><img src="img/head_icon2.png" style="width:2em;"></div>' + 
						// 		'	<div class="uma5 ut-s" style="width:4.4em;">' + res.result[i].name + '</div>' + 
						// 		'	<span class="more "></span>' + 
						// 		'</div>';
						html += '<li class="ctypeEvt" id="'+res.result[i]._id+'" data-id="'+res.result[i]._id+'">' +res.result[i].name+ '</li>';
					}
					$("#ctype").append(html);
					$(".ctypeEvt").click(function(){
						$(".ctypeEvt").removeClass("active_n");
						$(this).addClass("active_n");
						$(".iconImg").html('<img src="img/head_icon2.png" style="width:2em;">');
						// $(this).find(".iconImg").html('<img src="img/head_icon1.png" style="width:2em;">');
						listFn($(this).data("id"));
					});
				}
			});
			var listFn = function(ctype){
				$ajax({
					url: "/course/listFree",
					data:{
						status: 3,
						ctype: ctype
					},
					success: function(res) {
						var data = res.result;
						var coursesFree = "";
						for (var i = 0; i < data.length; i ++){
							// coursesFree += '<div class="threeList">';
							// for (var j = 0; j < 3; j ++){
							// 	if (!data[i*3+j])
							// 		continue;
							// 	var img = "img/t1.png";
							// 	if (data[i*3+j].photo)
							// 		img = Core.id2url(data[i*3+j].photo);
							// 	var teacherName = '';
							// 	if (data[i*3+j].teachers[0])
							// 		teacherName = data[i*3+j].teachers[0].name;
							// 	coursesFree +=  '<div class="singleC mycoursesFreeSin" data-id="' + data[i*3+j]._id + '">' + 
							// 					'	<img src="' + img + '" style="width:100%;height:223px;">' + 
							// 					'	<div class="ut-s" style="font-size:18px;padding-top:10px;">' + data[i*3+j].name + '</div>' + 
							// 					'	<div style="font-size:12px;">主讲老师 : ' + teacherName + '</div>' + 
							// 					'</div>';
							// 	if (j != 3)
							// 		coursesFree += '<div class="wh"></div>';						
							// }				
							// coursesFree += '</div>';
							var img = "img/t1.png";
							if (data[i].photo){
								img = Core.id2url(data[i].photo);
							}
							coursesFree += '<div class="box_n mycoursesFreeSin" data-id="' + data[i]._id + '">'+
											'	<dl>'+
											'		<dt><img src="' + img + '"></dt>'+
											'		<dd class="fs16">' + data[i].name + '</dd>'+
											'		<dd class="c80 ellipsis">' + data[i].des + '</dd>'+
											'	</dl>'+
											'</div>';
							if(i != 0 && (i+1)%4 == 0){
								coursesFree += '<div class="bor_n"></div>'
							}
						}
						$("#moreList").html(coursesFree);
						$(".mycoursesFreeSin").click(function(){
							window.location.href = "a_freeVideo.html?stype=coursefree&id=" + $(this).data("id");
						});
					}
				});		
			}
			listFn();
		}
		//讲师页面注掉
		else if (stype == "teacher"){	
			$("#listName").text("所有讲师");
			$ajax({
				url:"/users/list",
				data:{
					utype: UTYPE.TEACHER
				},
				success: function(res) {
					var data = res.result;
					var teacher = "";
					for (var i = 0; i < data.length/3; i ++){
						teacher += '<div class="threeList">';
						for (var j = 0; j < 3; j ++){
							if (!data[i*3+j])
								continue;
							var img = "img/t2.png";
							if (data[i*3+j].photo)
								img = Core.id2url(data[i*3+j].photo);
							teacher += '<div class="singleC myTeacherSin" data-id="' + data[i*3+j]._id + '">' + 
									'	<img src="' + img + '" style="width:100%;height:180px;">' + 
									'	<div style="font-size:15px;padding-top:10px;">讲师姓名 : ' + data[i*3+j].name + '</div>' + 
									'</div>';
							if (j != 3)
								teacher += '<div class="wh"></div>';						
						}				
						teacher += '</div>';
					}
					$("#moreList").html(teacher);
					$(".myteacherSin").click(function(){
						window.location.href = "a_indexDetailTeacher.html?stype=teacher&id=" + $(this).data("id");
					});
				}
			})
		}
	},
	studyInit: function(){
		if($.query.get('buy'))
			locaHref('a_indexStudy.html?'+random());
		var md5 = $.query.get("md5");
		var email_1 = $.query.get("username")?$.query.get("username"):CurrentUser.email;
		var coursecode = $.query.get('coursecode');
		if(md5 !='' && coursecode != '' ){
			$ajax({
				url:"/users/zlgn",
				data:{
					email:email_1, 
					coursecode:coursecode,
					md5: md5
				},
				success: function(res) {
					SetLS("user", res.result);
					CurrentUser = res.result;
					perhtml();
				}
			});
		}else{
			perhtml();
		}
		
		function perhtml(ww){
			$("#name").text(CurrentUser.name);
			var photo = 'img/tou1.jpg';
			if (CurrentUser.photo)
				photo = Core.id2url(CurrentUser.photo);
			$("#photo").attr("src",photo);
			var certificate = "";
			$ajax({
				url: "/users/findCertificateMatching",
				data: {
					id: CurrentUser._id,
					utype: CurrentUser.utype
				},
				success: function(res){
					//证书申请
					//alert(CurrentUser.utype);
							var apply = res.result;
							var htm="";
							for(var k=0; k<apply.length; k++){
							//alert()
							//var matching =parseInt(apply[i].matching);
							htm +=  '<div id="applyClick" class="myCertSingle applyBtn" data-applyid="'+ apply[k].id + '" style="cursor:pointer"> '+
										'<div><img src="/upload/'+apply[k].photo+'" style="width:100%;height:185px;"></div> ' +
										'<div style="width:41%;color:#333333">'+
										'<div class="slHao" style="margin-bottom: 1em;margin-top: 0.5em;font-size:18px;">'+ apply[k].name +'</div>	'+
										'<div class="courdes" style="font-size:16px;">'+		
										'<div style="padding: 0.5em 0.3em;" title="'+ apply[k].organization +'">颁证机构：<span class="slHao wid160 right">'+ apply[k].organization +'</span></div>	'+	
										'<div style="padding: 0.5em 0.3em;">｜</div>'+		
										'<div style="padding: 0.5em 0.3em;">认证学分：'+ apply[k].credit +'分</div>	'+		
										'</div>'+		
										'<div class="percent" style="margin-top:32%">'+	
										'<div class="graph" style="overflow: hidden;width:69%;">'+	
										'<div id="video" style="width:'+ apply[k].matching +'%">'+	
										'<span class="orange" style="-webkit-animation:leftShowIn 3s;-webkit-animation-fill-mode:both;-moz-animation:leftShowIn 3s;-moz-animation-fill-mode:both;-ms-animation:leftShowIn 3s;-ms-animation-fill-mode:both;height:24px; background-color:#4cbf73"></span>'+		
						                '</div>'+
						                '</div>'+      	
						                '<div class="zheng_p">匹配度 : '+ apply[k].matching +'%</div>'+ 
						                '</div>'+  
										'</div>'+
										'<div style="width:16%;text-align:center;position:relative"> '+	
										'<div style="position: absolute;right:40%"><img src="img/zheng_wu.png" alt="通过"></div>'+
										'<div id="studyBtn" class="shadow stubtn zheng_b">查看详情</div>'+	
										'</div> '+
										'<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%"></div>'+
										'</div>';
										
							}
							if (apply.length == 0){
									htm = 	'<div style="width:510px;margin:0 auto;padding-top: 10%;">' + 
													'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
													'	<div style="float:left;padding: 55px 0px 0px 15px;">我们无法为您匹配到证书,继续努力报名学习课程吧！</div>' + 
													'</div>';
								}
							$("#myApplyList").html(htm);
							$(".applyBtn").click(function(){
								//window.location.href = "a_indexStudyDetailCer.html?stype=certificate&id=" + $(this).data("id");
								window.location.href = "a_indexStudyApply.html?id=" + $(this).data("applyid");
							});
						//我的证书
						$ajax({
							url: "/users/findMyCertificateList",
							data: {
								id: CurrentUser._id,
								utype: CurrentUser.utype
							},
							success: function(res){
								var myCer = res.result;
								myCer.sort(function(a,b) {return a.cerStatus - b.cerStatus;});
								//console.log(myCer);
								//一共有几门课 myCer.courses.length
								var certificatePercent =0;
								var learninghtml = "";
								var applyhtml = "";
								var nosubhtml = '';
								var overdue = false;
								var overCer = [];
								var learnCer = [];
								//遍历证书				
								for (var i = 0; i < myCer.length; i ++){
									var src = 'img/t1.png';
									var cerSta = '';
									var margin = "margin:0 0 0 50px";
									var hidden = "hidden";
									if (myCer[i].photo)
										src = Core.id2url(myCer[i].photo);
									var express = '';
									//计算证书进度
									var coursePercent = 0;
									var courseNum = 0;
									for(var j=0; j<myCer[i].courses.length; j++){
										if(myCer[i].courses[j].SumScore != "" && myCer[i].courses[j].SumScore !=0){
											coursePercent += parseInt( myCer[i].courses[j].progress);
											courseNum++;
										}
									}
									for(var zz=0; zz<myCer[i].coursesChoosable.length; zz++){
										if(myCer[i].coursesChoosable[zz].SumScore != "" && myCer[i].coursesChoosable[j].SumScore !=0){
											coursePercent += parseInt( myCer[i].coursesChoosable[zz].progress);
											courseNum++;
										}
									}
									//alert(certificatePercent);
									certificatePercent = courseNum>0?(coursePercent/courseNum):0;
									certificatePercent = parseInt(certificatePercent);
									// if (myCer[i].cerStatus == STATUS.CERTIFICATE_FINISH)
									// 	express = 	'<div class="courdes" style="padding:0.5em 0;">' + 
									// 				'	<div style="margin-right:1em;">快递公司 : ' + myCer[i].express.name + '</div>' + 	
									// 				'	<div>运单号 : ' + myCer[i].id + '</div>' + 		
									// 				'</div>';

									if (myCer[i].cerStatus == 2)
										cerSta = '<img src="/img/zheng_she.png" style="margin:7px 0px 50px 55px">';
									else if(myCer[i].cerStatus == 3 || myCer[i].cerStatus >= 5)
										cerSta = '<img src="/img/zheng_tong.png" style="margin:7px 0px 50px 55px">';
									else if(myCer[i].cerStatus == 4)
										cerSta = '<img src="/img/zheng_jj.png" style="margin:7px 0px 50px 55px">';
									else if(myCer[i].cerStatus == 1){//学习中状态判定 课程是否过期
										for (var fm = 0; fm < myCer[i].courses.length; fm++) {
											if(myCer[i].courses[fm].validity > 0){
												overdue = true;
												learnCer.push(myCer[i]);
												break;
											}else{
												overCer.push(myCer[i]);
												break;
											}
										}
										if(!overdue){
											cerSta = '<img src="/img/zheng_wsq.png" style="margin:7px 0px 50px 55px">';
											hidden = "";
										}
										else{
											margin = "";
											hidden = "";
										}
									}
									else{
										margin = "";
										hidden = "";
									}
									certificate += 	'<div class="myCertSingle stuBt" data-id="' + myCer[i].id + '" style="cursor:pointer">' + 
													'	<div><img src="' + src + '" style="width:100%;height:185px;"></div>' + 
													'	<div style="width:41%;font-size:16px;margin-bottom:0;margin-right:0">' + 
													'		<div class="slHao" style="margin-bottom: 1em;margin-top: 0.5em;font-size:18px;">' + myCer[i].name + '</div>' + 		
													//注释掉费用
													// '		<div class="courdes" >' + 
													// '			<div>费用 : ' + CurrentUser.certificate[i].fee + ' 元</div>' + 		
													// '		</div>' + 
													'		<div class="courdes">' + 
														'		<div style="padding: 0.5em 0em;">颁证机构：<span class="slHao wid160 right">' + myCer[i].organization +'</span></div>'+
														'		<div style="padding: 0.5em 0.3em;">｜</div>'	+
														'		<div style="padding: 0.5em 0.3em;">认证学分：'+ (myCer[i].credit ==undefined ?'0': myCer[i].credit) +' 分</div>'+
													'		</div>' + 
													// '		<div style="clear:both;padding-top:1em;font-size:1em;min-height:38px">纸质证书状态 : ' + STATUS_HTML[myCer[i].cerStatus] + '</div>' + 
													'       <div style="clear:both;padding-top:1em;font-size:1em;min-height:38px"></div>'+
													'	<div class="percent '+hidden+'" style="margin-top:30px;">'+
								                    '	<div class="graph" style="overflow: hidden;width:69%;">'+
								                    '		<div id="video" style="width:'+ certificatePercent +'%;">'+
								                    '			<span class="orange" style="-webkit-animation:leftShowIn 3s;-webkit-animation-fill-mode:both;-moz-animation:leftShowIn 3s;-moz-animation-fill-mode:both;-ms-animation:leftShowIn 3s;-ms-animation-fill-mode:both;"></span>'+
								                    '		</div>'+
								                    '	</div>'+
								                    '	<div style="width:31%;padding:0 0.4em;font-size:0.8em;font-size:16px">进度 : '+ certificatePercent +'%</div>'+
								                    '	</div>'+
													express + 			
													'		<div style="clear:both;padding-top:1em;">' + 
													// '			<div>' + CurrentUser.certificate[i].des + '</div>' + 
													'		</div>' + 		
													'	</div>' + 
													'	<div style="width:16%;text-align:center;">' + cerSta +
													'		<div id="studyBtn" class="shadow stubtn zheng_b" style="'+margin+'">查看详情</div>' + 
													'	</div>' + 
													'	<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%;"></div>'+	
													'</div>' ; 
									learnCer.concat(learnCer);
									var learleng = myCer.length-1;
									if(learnCer.length >0 && i == learleng){
										for(var ln=0;ln<learnCer.length;ln++){
											learninghtml += '<div class="myCertSingle stuBt" data-id="' + learnCer[ln].id + '" style="cursor:pointer">' + 
															'	<div><img src="' + Core.id2url(learnCer[ln].photo) + '" style="width:100%;height:185px;"></div>' + 
															'	<div style="width:41%;font-size:16px;margin-bottom:0;margin-right:0">' + 
															'		<div class="slHao" style="margin-bottom: 1em;margin-top: 0.5em;font-size:18px;">' + learnCer[ln].name + '</div>' + 		
															//注释掉费用
															// '		<div class="courdes" >' + 
															// '			<div>费用 : ' + CurrentUser.certificate[i].fee + ' 元</div>' + 		
															// '		</div>' + 
															'		<div class="courdes">' + 
															'		<div style="padding: 0.5em 0em;">颁证机构：<span class="slHao wid160 right"> ' + learnCer[ln].organization +'</span></div>'+
															'		<div style="padding: 0.5em 0.3em;">｜</div>'	+
															'		<div style="padding: 0.5em 0.3em;">认证学分：'+ (learnCer[ln].credit ==undefined ?'0': learnCer[ln].credit) +' 分</div>'+
															'		</div>' + 
															// '		<div style="clear:both;padding-top:1em;font-size:1em;min-height:38px">纸质证书状态 : ' + STATUS_HTML[myCer[i].cerStatus] + '</div>' + 
															'       <div style="clear:both;padding-top:1em;font-size:1em;min-height:38px"></div>'+
															'	<div class="percent '+hidden+'" style="margin-top:30px;">'+
										                    '	<div class="graph" style="overflow: hidden;width:69%;">'+
										                    '		<div id="video" style="width:'+ certificatePercent +'%;">'+
										                    '			<span class="orange" style="-webkit-animation:leftShowIn 3s;-webkit-animation-fill-mode:both;-moz-animation:leftShowIn 3s;-moz-animation-fill-mode:both;-ms-animation:leftShowIn 3s;-ms-animation-fill-mode:both;"></span>'+
										                    '		</div>'+
										                    '	</div>'+
										                    '	<div style="width:31%;padding:0 0.4em;font-size:0.8em;font-size:16px">进度 : '+ certificatePercent +'%</div>'+
										                    '	</div>'+
															express + 			
															'		<div style="clear:both;padding-top:1em;">' + 
															// '			<div>' + CurrentUser.certificate[i].des + '</div>' + 
															'		</div>' + 		
															'	</div>' + 
															'	<div style="width:16%;text-align:center;">' + cerSta +
															'		<div id="studyBtn" class="shadow stubtn zheng_b" style="'+margin+'">查看详情</div>' + 
															'	</div>' + 
															'	<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%;"></div>'+
															'</div>' ;
											
										}
										$("#learningCer").html(learninghtml);
									}
									if(myCer[i].cerStatus  >1){
										applyhtml += '<div class="myCertSingle stuBt"  data-id="' + myCer[i].id + '" style="cursor:pointer">' + 
														'	<div><img src="' + src + '" style="width:100%;height:185px;"></div>' + 
														'	<div style="width:41%;font-size:16px;margin-bottom:0;margin-right:0">' + 
														'		<div class="slHao" style="margin-bottom: 1em;margin-top: 0.5em;font-size:18px;">' + myCer[i].name + '</div>' + 		
														//注释掉费用
														// '		<div class="courdes" >' + 
														// '			<div>费用 : ' + CurrentUser.certificate[i].fee + ' 元</div>' + 		
														// '		</div>' + 
														'		<div class="courdes">' + 
														'		<div style="padding: 0.5em 0em;">3颁证机构：<span class="slHao wid160 right"> ' + myCer[i].organization +'</span></div>'+
														'		<div style="padding: 0.5em 0.3em;">｜</div>'	+
														'		<div style="padding: 0.5em 0.3em;">认证学分：'+ (myCer[i].credit ==undefined ?'0': myCer[i].credit) +' 分</div>'+
														'		</div>' + 
														// '		<div style="clear:both;padding-top:1em;font-size:1em;min-height:38px">纸质证书状态 : ' + STATUS_HTML[myCer[i].cerStatus] + '</div>' + 
														'       <div style="clear:both;padding-top:1em;font-size:1em;min-height:38px"></div>'+
														'	<div class="percent '+hidden+'" style="margin-top:30px;">'+
									                    '	<div class="graph" style="overflow: hidden;width:69%;">'+
									                    '		<div id="video" style="width:'+ certificatePercent +'%;">'+
									                    '			<span class="orange" style="-webkit-animation:leftShowIn 3s;-webkit-animation-fill-mode:both;-moz-animation:leftShowIn 3s;-moz-animation-fill-mode:both;-ms-animation:leftShowIn 3s;-ms-animation-fill-mode:both;"></span>'+
									                    '		</div>'+
									                    '	</div>'+
									                    '	<div style="width:31%;padding:0 0.4em;font-size:0.8em;font-size:16px">进度 : '+ certificatePercent +'%</div>'+
									                    '	</div>'+
														express + 			
														'		<div style="clear:both;padding-top:1em;">' + 
														// '			<div>' + CurrentUser.certificate[i].des + '</div>' + 
														'		</div>' + 		
														'	</div>' + 
														'	<div style="width:16%;text-align:center;margin-left:21px">' + cerSta +
														'		<div id="studyBtn" class="shadow stubtn zheng_b" style="'+margin+'">查看详情</div>' + 
														'	</div>' + 
														'	<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%"></div>'+
														'</div>' ;
															
										}
									}
									if (myCer.length == 0){
										// $(".zheng_sx").addClass("hidden");
										certificate = 	'<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
														'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
														'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有相应的证书,马上<a href="a_indexMoreList.html?stype=certificate" style="cursor:pointer;">去看看</a>吧</div>' + 
														'</div>';
									}
									if(overCer.length>0){
										for(var nv=0;nv<overCer.length;nv++){
											nosubhtml += '<div class="myCertSingle stuBt" data-id="' + overCer[nv].id + '" style="cursor:pointer">' + 
															'	<div><img src="' + src + '" style="width:100%;height:185px;"></div>' + 
															'	<div style="width:41%;font-size:16px;margin-bottom:0;margin-right:0">' + 
															'		<div class="slHao" style="margin-bottom: 1em;margin-top: 0.5em;font-size:18px;">' + overCer[nv].name + '</div>' + 		
															//注释掉费用
															// '		<div class="courdes" >' + 
															// '			<div>费用 : ' + CurrentUser.certificate[i].fee + ' 元</div>' + 		
															// '		</div>' + 
															'		<div class="courdes">' + 
															'		<div style="padding: 0.5em 0em;">颁证机构：<span class="slHao wid160 right"> ' + overCer[nv].organization +'</span></div>'+
															'		<div style="padding: 0.5em 0.3em;">｜</div>'	+
															'		<div style="padding: 0.5em 0.3em;">认证学分：'+ (overCer[nv].credit ==undefined ?'0': overCer[nv].credit) +' 分</div>'+
															'		</div>' + 
															// '		<div style="clear:both;padding-top:1em;font-size:1em;min-height:38px">纸质证书状态 : ' + STATUS_HTML[overCer[i].cerStatus] + '</div>' + 
															'       <div style="clear:both;padding-top:1em;font-size:1em;min-height:38px"></div>'+
															'	<div class="percent '+hidden+'" style="margin-top:30px;">'+
										                    '	<div class="graph" style="overflow: hidden;width:69%;">'+
										                    '		<div id="video" style="width:'+ certificatePercent +'%;">'+
										                    '			<span class="orange" style="-webkit-animation:leftShowIn 3s;-webkit-animation-fill-mode:both;-moz-animation:leftShowIn 3s;-moz-animation-fill-mode:both;-ms-animation:leftShowIn 3s;-ms-animation-fill-mode:both;"></span>'+
										                    '		</div>'+
										                    '	</div>'+
										                    '	<div style="width:31%;padding:0 0.4em;font-size:0.8em;font-size:16px">进度 : '+ certificatePercent +'%</div>'+
										                    '	</div>'+
															express + 			
															'		<div style="clear:both;padding-top:1em;">' + 
															// '			<div>' + CurrentUser.certificate[i].des + '</div>' + 
															'		</div>' + 		
															'	</div>' + 
															'	<div style="width:16%;text-align:center;">' +
															'		<img src="/img/zheng_wsq.png" style="margin:7px 0px -90px 55px">'+
															'		<div id="studyBtn" class="shadow stubtn zheng_b" style="'+margin+'">查看详情</div>' + 
															'	</div>' + 
															'	<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%;"></div>'+
															'</div>' ;
										}
										$("#nosubmitCer").html(nosubhtml);
									}
									if (overCer.length == 0){
										nosubhtml = '<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
													'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
													'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有已过期未申请的证书</div>' + 
													'</div>';
										$("#nosubmitCer").html(nosubhtml);
									}
									if (learninghtml.length == 0){
										learninghtml = 	'<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
														'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
														'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有相应的证书,赶紧<a href="a_indexMoreList.html?stype=certificate" style="cursor:pointer;">去看看</a>吧</div>' + 
														'</div>';
										$("#learningCer").html(learninghtml);
									}
									//$("#firstBtn").html(firstBtnhtml);
									$("#allCer").html(certificate);
									$("#learningCer").html(learninghtml);
									if(applyhtml.length == 0){
											applyhtml = 	'<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
														'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
														'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有已申请的证书</div>' + 
														'</div>';
									}
									$("#submitCer").html(applyhtml);

									//助力计划跳转进来的情况
									if(md5){
										window.location.href = "#myCertificateList";
										$("#cara").addClass("selected");
										Signup.showLists(CurrentUser.photo, CurrentUser.name);
									}

									$("#all_").click(function(){
										$("#allCer").removeClass('hidden');
										$("#learningCer").addClass('hidden');
										$("#submitCer").addClass('hidden');
										$("#nosubmitCer").addClass('hidden');
									});
									$("#all_1").click(function(){
										$("#learningCer").removeClass('hidden');
										$("#allCer").addClass('hidden');
										$("#submitCer").addClass('hidden');
										$("#nosubmitCer").addClass('hidden');
									});
									$("#all_2").click(function(){
										$("#submitCer").removeClass('hidden');
										$("#learningCer").addClass('hidden');
										$("#allCer").addClass('hidden');
										$("#nosubmitCer").addClass('hidden');
									});
									$("#all_3").click(function(){
										$("#nosubmitCer").removeClass('hidden');
										$("#submitCer").addClass('hidden');
										$("#learningCer").addClass('hidden');
										$("#allCer").addClass('hidden');
									});
									$(".stuBt").click(function(){
										//window.location.href = "a_indexStudyDetailCer.html?stype=certificate&id=" + $(this).data("id");
										window.location.href = "a_indexStudyDetailCer.html?id=" + $(this).data("id");
									});
								}
							});
				}
			});
			

			//我的课程
			//过滤掉倒入证书包含的课程
			var myCourseShow = [];
			//alert(CurrentUser.course);
			$ajax({
				url: '/users/stuCourseId',
				data: {uid: CurrentUser._id},
				success: function(res){
					for(var i=0; i<res.result.length; i++){
						if(res.result[i].withCertificate == false){
							//myCourseShow.push(CurrentUser.course[i].id);
							myCourseShow.push(res.result[i].id);
						}
					}
					//console.log(myCourseShow);
					if(myCourseShow.length != 0){
						$ajax({
							url: "/users/stuMyCourseList",
							data: {
								courses: myCourseShow,
								id: CurrentUser._id
							},
							success: function(res){
								var data = res.result;
								var course = "";
								if (typeof(data) == "undefined"){
									course = 	'<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
													'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
													'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有课程,马上<a href="a_indexMoreList.html?stype=course" style="cursor:pointer;">去看看</a>吧</div>' + 
													'</div>';
									return $("#myCourseList").html(course);
								}
								for (var i = data.length-1; i >= 0; i --){
									var src = 'img/t1.png';
									var teacherName = '';
									var teacherPhoto = '';
									var expiryDate = data[i].expiryDate;
									var days="  ", month="  ", year="  ";
									var stuBtmCss = "stubtn";
									var stuBtmCss2 = "";
									var stuBtmCss3 = "hidden";
									var value=1;
									var proportion = data[i].progress;
									if (data[i].photo)
										src = Core.id2url(data[i].photo);
									if (data[i].teacher)
										teacherName = data[i].teacher;
									if (data[i].teacherPhoto)
										teacherPhoto = Core.id2url(data[i].teacherPhoto);
									if (typeof(expiryDate) != "undefined" && expiryDate != ""){
										var a = expiryDate.split('T');
										var b = a[0].split('-');
										days = b[2];
										if(days.length < 2)
											days = '0'+days;
										month = b[1];;
										if(month.length < 2) month = '0'+month;
											year = b[0];;
									}
									//未激活不可以学习
									if(data[i].status == "false"){
										stuBtmCss = "disable_stubtn";
										//$("#studyBtn").innerHTML='已锁定';
									}
									//判断有效期
									if(data[i].expiryDate){
										if(data[i].validity==0)
											value=0;
									}
									//计算课程是否合格用于显示图片
									//console.log(data[i]);
									var courseStudy = "";
									var beginlerning = "";
									if(data[i].validity==0){
				            			if(parseInt(data[i].SumScore) < 60 && parseInt(data[i].SumScore) >= 0){
			            					stuBtmCss3 ="";
			            					beginlerning ="报名学习";
				            				if(data[i].proAttr == 1)
				            					stuBtmCss2 = "z_bgC";
				            				courseStudy = "img/zheng_bh.png";
				            			}else if(parseInt(data[i].SumScore) >=60){
			            					stuBtmCss3 ="";
			            					stuBtmCss2 = "z_bgC";
			            					beginlerning ="课程结束";
			            					courseStudy = "img/zheng_he.png";
				            			}
			            			}else{
		        						beginlerning ="开始学习";
		            					courseStudy = "img/zheng_wu.png";
				            		}
				            		/* 判断定金课程 2017年6月9日10:20:47 G */
				            		var tmp = '';
				            		if ( data[i].name == IndexStudent.CONST_COUR_NAME ) {
				            			if (data[i].expiryDate) {
				            				tmp = 
				            					'<div style="clear:both"></div>' + 
										       	'<div class="timeEnd" style="margin-top:7%;">有效期至：<b>${year}</b> 年<b> ${month}</b> 月<b> ${days}</b> 日</div>' +
										     '';
				            			} else {
				            				tmp = 
				            					'<div style="clear:both"></div>' +
												'<div class="timeEndPlaceholder"></div>' +
											'';
				            			}
				            			course += 
					            			'<div class="myCourse" data-value="${value}" style="cursor:pointer">' +
											    '<div><img src="${teacherPhoto}" style="width:100%;height:185px;"></div>' +
											    '<div style="width:38%;">' +
											        '<div class="slHao" style="margin-bottom: 1em;font-size:16px">${IndexStudent.CONST_COUR_NAME}</div>' +
													tmp +
											    '</div>' +
											    '<div style="width:16%;text-align:center;position:relative">' +
											        '<div id="src" class="" style="position: absolute;"><img src="img/zheng_wu.png" alt="通过"></div>' +
											        '<div class="myCour_fen hidden"><span class="bg_y" style="padding-left:0px;">0</span> 分</div>' +
											        '<div class="shadow zheng_b stubtn ">缴费成功</div>' +
											    '</div>' +
											    '<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%"></div>' +
											'</div>' +
										'';
				            		} else {
				            		/* end */
										course +='<!-- 我的课程 -->' +
														'<div class="myCourse" data-pro="'+ data[i].proAttr +'" data-sumSocer="'+data[i].SumScore+'" data-status="'+ data[i].status +'" data-value="'+ value +'" data-id="' + data[i].id + '" style="cursor:pointer">' +
														'	<div><img src="' + src + '" style="width:100%;height:185px;"></div>' +
														'	<div style="width:38%;">' +
														'		<div class="slHao" style="margin-bottom: 1em;font-size:16px">' + data[i].name + '</div>' +
														'		<div class="courdes" style="font-size:16px">' +
														'			<div><img src="' + teacherPhoto + '" style="width:3em;height:3em;border-radius:50%;"></div>' +
														'			<div style="padding: 0.5em 0.3em;">主讲教师 : ' + teacherName + '</div>' +
														'			<div style="padding: 0.5em 0.3em;">｜</div>' +
														'			<div style="padding: 0.5em 0.3em;">认证学分：' + data[i].credit + '分</div>' +	
														'		</div>';
										if((typeof(data[i].expiryDate) != "undefined") && data[i].expiryDate != "") { 
											course +=
														'<div style="clear:both"></div>' +
														'<div class="timeEnd" style="margin-top:7%;">有效期至：<b>' + year + '</b> 年<b> ' + month + '</b> 月<b> ' + days + '</b> 日</div>';
										} else {
											course +=
														'<div style="clear:both"></div>' +
														'<div class="timeEndPlaceholder"></div>';
										}
										course +=
														'<div class="percent" style="margin-top:3%">' +
														'			<div class="graph" style="overflow: hidden;width:69%;">' +
													    '                      <div id="video" style="width:' + proportion + '%">' +
													    '                      	<span class="orange" style="-webkit-animation:leftShowIn 3s;-webkit-animation-fill-mode:both;-moz-animation:leftShowIn 3s;-moz-animation-fill-mode:both;-ms-animation:leftShowIn 3s;-ms-animation-fill-mode:both;"></span>' +
													    '                      </div>' +
													    '                  </div>' +
																'			<div style="width:31%;padding:0 0.4em;font-size:0.8em;font-size:16px">进度 : ' + parseInt(proportion)  + '%</div>' +
																'		</div>' +
																'	</div>' +
																'	<div style="width:16%;text-align:center;position:relative">' +
																'		<div id="src" class="" style="position: absolute;"><img src='+ courseStudy +' alt="通过"></div>'+
																'		<div class="myCour_fen '+ stuBtmCss3 +'"><span class="bg_y" style="padding-left:0px;">'+ data[i].SumScore +'</span> 分</div>'+
																'		<div id="studyBtn" class="shadow zheng_b '+stuBtmCss+' '+ stuBtmCss2 +'" style="">'+ beginlerning +'</div>' +
																'	</div>' +
																'	<div style="clear:both;border-bottom:1px solid #cccccc;margin:0 auto;margin-left:1%;width:100%"></div>' +
																'</div>' +
																'<!-- end -->';
										}
									}
									if (data.length == 0){
										course = 	'<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
														'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
														'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有相应的课程,马上<a href="a_indexMoreList.html?stype=course" style="cursor:pointer;">去看看</a>吧</div>' + 
														'</div>';
									}
									$("#myCourseList").append(course);
									$("#courAll").click(function(){
										$("#myCourseList").children("div").removeClass("hidden");
									});
									$("#courStudying").click(function(){
										$("#myCourseList").children("div").each(function(){
											var value = 0;
												value = $(this).data("value");
												if(value == 0){
													$(this).addClass("hidden");
													$(this).next("div").addClass("hidden");
												}else{
													$(this).removeClass("hidden");
													$(this).next("div").removeClass("hidden");
												}
										})
									}).click();
									$("#courEnd").click(function(){
										$("#myCourseList").children("div").each(function(){
											var value = 1;
												value = $(this).data("value");
												if(value == 1){
													$(this).addClass("hidden");
													$(this).next("div").addClass("hidden");
												}else{
													$(this).removeClass("hidden");
													$(this).next("div").removeClass("hidden");
												}
										})
									});

									$(".myCourse").click(function(){
										/* 设置定金课程拦截 2017年6月9日11:13:36 G */
										var _title = $(this).find('.slHao').html();
										if ( _title == IndexStudent.CONST_COUR_NAME ) {
											return;
										}
										if($(this).data("status")){
											if($(this).data("value")== 1){
												var pro = $(this).data('pro');
												// if(pro == 1 || pro == '1')
												// 	window.location.href = "studyPlan.html?stype=course&id=" + $(this).data("id")+ "&pro="+pro;
												// else
													window.location.href = "a_s_courseLearning.html?stype=course&id=" + $(this).data("id")+ "&pro="+pro;
												//window.location.href = "a_indexDetailCourse.html?stype=course&id=" + $(this).data("id");
											}else{
												var text=$(this).find("#studyBtn").text();
												if(text =="报名学习" || text =="课程结束"){
													if($(this).data('pro') != 1)
														window.location.href = "a_indexDetailCourseFirst.html?stype=notvalue&stype=course&id=" +$(this).data("id");
												}
											}
										}else{
											alert("您的这门课程已锁定，请学习其他课程或联系相关人员！！！");
										}
									});
							}
						});
					}else{
						var ht = '<div id="nocou"><div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
															'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
															'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有相应的课程,马上<a href="a_indexMoreList.html?stype=course" style="cursor:pointer;">去看看</a>吧</div>' + 
															'</div></div>';
						$("#myCourseList").append(ht);
						$("#courEnd").click(function(){
						$("#nocou").empty();
						var	ht = '<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
								'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
								'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有学习已结束的课程</div>' + 
								'</div>';
						$("#nocou").append(ht);
						});
						$("#courStudying").click(function(){
							$("#nocou").empty();
								var	ht = '<div style="width:365px;margin:0 auto;padding-top: 10%;">' + 
										'	<div style="float:left;"><img src="img/photo_1.png"></div>' + 
										'	<div style="float:left;padding: 55px 0px 0px 15px;">您还没有相应的课程,马上<a href="a_indexMoreList.html?stype=course" style="cursor:pointer;">去看看</a>吧</div>' + 
										'</div>';
								$("#nocou").append(ht);
						});
					}
				}
			})
			
			$ajax({
				url : "/users/applyInvoice",
				data: {id: CurrentUser._id},
				success: function(res){
					if(res.result.length > 0){
						$('#shenFv').attr("href", "a_applyInvoice.html");
					}else{
						$('#shenFv').click(function(){
							$("body,html").animate({scrollTop:0},0);
							$('.tan_x').show();
							$('.tan_x').height($(document).height());
							$('#tan_all').slideDown(200);
							$('#tan_all').width(500);
						});
						$('.tan-poptit .close,#cancel').click(function(){
							$('.tan_x').hide();
							$('#tan_all').slideUp(200);
						});
					}
				}
			});
		}
	},
	detailStudyInit: function(){
		var stype = $.query.get("stype");
		var id = $.query.get("id");
		var releCou = true;
		if(id == '5930c239e92440775bd7eddc'){//要处理证书的 ＩＤ
			$('.takeCer').css('display','none');
			releCou = false;
		}

		$ajax({
			url: "/certificate/detail",
			data:{
				_id : id
			},
			success: function(res) {
				$("#cname").text(res.result.name);
				// .attr("href","a_indexMoreList.html?stype=course&ctypeid=" + res.result.ctype);
				$("#ctypeName").attr("href","a_indexMoreList.html?stype=certificate&ctypeid=" + res.result.ctype);
				$("#certificateType").text(res.result.certificateType);
				window.document.title = res.result.name+'-国开享学吧';

				for (var key in res.result){
					if (key == "photo")
					{
						if (res.result.photo) {
							$("#photo").attr("src",Core.id2url(res.result.photo));
							$("#banner_bg_n").css("backgroundImage","url("+Core.id2url(res.result.photo)+")");
						} else {
							$("#photo").attr("src","img/tou1.jpg");
							$("#banner_bg_n").css("backgroundImage","url(img/tou1.jpg)");
						}
					} else if (key == "create") {
						$("#create").text((new Date(res.result.create)).pattern("yyyy-MM-dd HH:mm:ss"));
					} else {
						$("#" + key).html(res.result[key]);
					}
				}
				$("#cnamea").text(res.result.name);
				$("#processa").html('<img src="upload/'+ res.result.process +'">')
				// 关联课程
				var course = "";
				var glcour = "";

				// 最多4个 
				for (var i = 0; i < res.result.courses.length; i ++){
					if (!res.result.courses[i])
						continue;
					var img = "img/t1.png";
					if (res.result.courses[i].photo)
						img = Core.id2url(res.result.courses[i].photo);
					var teacherPhoto = "img/tou2.jpg";
					if (res.result.courses[i].teachers[0]) {
						if (res.result.courses[i].teachers[0].photo)
							teacherPhoto = Core.id2url(res.result.courses[i].teachers[0].photo);
					}	
					var teacherName = '';
					if (res.result.courses[i].teachers[0]){
						if (res.result.courses[i].teachers[0].name)
							teacherName = res.result.courses[i].teachers[0].name;
					}
					var credit = '0';
					if (res.result.courses[i].credit)
						credit = res.result.courses[i].credit;

					course +=	'<div class="box_n addcour shadow xx_zs singleC" data-id="' + res.result.courses[i]._id + '">' +
								'	<dl>' +
								'		<dt><img src="' + img + '"></dt>' +
								'		<dd class="fs16 ellipsis"  style="border-bottom: 1px solid #E6E6E6;">' + res.result.courses[i].name + '</dd>' +
								'		<div class="addshouke" style="height:45px;padding-bottom:10px">' +
								'			<span style="width:40px;padding:0"><img src="' + teacherPhoto + '"></span>' +
								'			<span style="padding-right:15px">授课老师：'+teacherName+'</span>' +
								'			<span style="padding:0">认证学分：' + credit + '学分</span>' +
								'		</div>' +
								'	</dl>' +
							    '</div>	';
					if(i>3){
						course += '<div class="clear"></div><div class="xx_more fs14 moreGl">查看更多</div>';
						break;
					}				
				}

				$("#courseList").append(course);
				$(".moreGl").on("click",function(){
					$(".zscerti").addClass("none");
					$(".glcour").removeClass("none");
					$('html, body').animate({scrollTop: 300}, 100);
				})
				// 显示全部
				for (var i = 0; i < res.result.courses.length; i ++){
					if (!res.result.courses[i])
						continue;
					var img = "img/t1.png";
					if (res.result.courses[i].photo)
						img = Core.id2url(res.result.courses[i].photo);
					var teacherPhoto = "img/tou2.jpg";
					if (res.result.courses[i].teachers[0]) {
						if (res.result.courses[i].teachers[0].photo)
							teacherPhoto = Core.id2url(res.result.courses[i].teachers[0].photo);
					}	
					var teacherName = '';
					if (res.result.courses[i].teachers[0]){
						if (res.result.courses[i].teachers[0].name)
							teacherName = res.result.courses[i].teachers[0].name;
					}
					var credit = '0';
					if (res.result.courses[i].credit){
						credit = res.result.courses[i].credit;
					}

					glcour +=   '<div class="box_n addcour gcour shadow singleC" data-id="' + res.result.courses[i]._id + '">'+
								'	<dl>'+
								'		<dt><img src="' + img + '"></dt>'+
								'		<dd class="fs16">' + res.result.courses[i].name + '</dd>'+
								'		<dd class="c80 ellipsis" style="border-bottom: 1px solid #E6E6E6;">' + res.result.courses[i].des + '</dd>'+
								'		<div class="addshouke">'+
								'			<h2 class="fl" style="padding-right:10px"><img src="' + teacherPhoto + '"></h2>'+
								'			<span class="fl">主讲老师：' + teacherName + '</span>'+
								'			<span class="fr">学分认证：' + credit + '学分</span>'+
								'		</div>'+
								'	</dl>'+
								'</div>';		
				}
				
				$("#glcour").html(glcour);
				$(".singleC").click(function(){
					if(releCou)//当证书为：软件开发工程师（初级）岗位技能培训证书 不允许跳转
						window.location.href = "a_indexDetailCourseFirst.html?stype=course&id=" + $(this).data("id");
				});
				// var samples = '';
				// for (var i = 0; i < res.result.samples.length; i ++){
				// 	var src = Core.id2url(res.result.samples[i]);
				// 	samples += 	'<div style="color: #888;font-size: 10px;border:1px solid #CCCCCC;text-align:center;padding:1em;margin-bottom: 1em;margin:1em auto;">' + 
				// 				'	<img src="' + src + '">' + 
				// 				'</div>';
				// }
				// $("#samples").html(samples);
				if($.query.get('certipay') == 'true')
					var pay = '<div id="payBtn" class="btn_xx shad_b2">我要报名</div>';
				else 
					var pay = '<div style="background-color: rgb(197, 190, 190);" class="btn_xx shad_b2">购买证书</div>';
				console.log(CurrentUser);//打印
				if(CurrentUser.utype == 1000){
					$("#pay").html(pay);
					$("#payBtn").click(function(){
						$("#lbtn").click();
					});
				}
				if(CurrentUser.utype != 1000){
					var flag = false;
					for(var i = 0; i < CurrentUser.certificate.length; i ++){
						if (CurrentUser.certificate[i].id == res.result._id){
							flag = true;
						}
					}
					if (!flag){
						var isRenew = 1;
						var btnName = "报名取证";
						$("#pay").html(pay);
						$("#payBtn").click(function(){
							//to do..调用第三方付款
							window.location.href = "a_indexStudentPay.html?cid="+res.result._id+"&fee="+res.result.fee+"&cname="+res.result.name+"&type=1&validity="+ res.result.validity +"&isRenew="+isRenew+"&pType="+res.result.ctype;
							//IndexStudent.buyCourse(res.result._id, res.result.fee, res.result.name);	
						});
					}
					if($.query.get("goto") == "1")
						$("#payBtn").click();
				}	
			}
		});
	},
	detailTeacherInit: function(){
		var stype = $.query.get("stype");
		var id = $.query.get("id");

		$ajax({
			url: "/teacher/detail",
			data:{
				_id : id
			},
			success: function(res) {
				var img = "img/t1.png";
				if (res.result.photo)
					img = Core.id2url(res.result.photo);
				$("#photo").attr("src",img);
				for (var key in res.result){
					$("#" + key).text(res.result[key]);
				}
				var html = '';
				for(var i = 0; i < res.result.courses.length; i ++){
					var cimg = "img/t1.png";
					if (res.result.courses[i].photo)
						cimg = Core.id2url(res.result.courses[i].photo);
					var teacherName = '';
					if (res.result.courses[i].teachers[0])
						teacherName = res.result.courses[i].teachers[0].name;
					var credit = '0';
					if (res.result.courses[i].credit)
						credit = res.result.courses[i].credit;
					html += '<div class="singleC courEvt" data-id="' + res.result.courses[i]._id + '" style="width:48%;margin-right:2%;">' + 
							'	<img src="' + cimg + '" style="width:100%;height:200px;">' + 
							'	<div style="font-size:16px;font-weight:bold;padding-top:10px;margin-left: 0.5em;">' + res.result.courses[i].name + '</div>' + 
							'	<div style="font-size:12px">' + 
							'		<span style=""><img src="' + img + '" style="width:3em;height:3em;border-radius: 50%;"></span>' + 
							'		<span style="margin-right:1.2em;">主讲教师: ' + res.result.name + '</span>' +
							'		<span style="float:right;margin:0.7em 0.7em 0 0;">认证学分: ' + credit + '分</span>' + 
							'	</div>' + 
							'</div>';
				}
				$("#courseList").append(html);
				$(".courEvt").click(function(){
					window.location.href = "a_indexDetailCourseFirst.html?stype=course&id=" + $(this).data("id");
				});
				window.document.title = res.result.name+'-国开享学吧';
			}
		});
	},
	detailCourseFirstInit: function(){
		var id = $.query.get("id");
		var stype = $.query.get("stype");
		$ajax({
			url:"/course/detailCourse",
			data:{
				_id : id
			},
			success: function(res) {
				function isNoFeeCourse(idd) {
					var css = ["59925dd3ad13867dd956510d", "59925e06ad13867dd956510f", "59925e48ad13867dd9565110", 
								"59925e5bad13867dd9565111", "59925e6cad13867dd9565112", "59925e79ad13867dd9565113", 
								"59925e87ad13867dd9565114", "59925e97ad13867dd9565115", "59925eabad13867dd9565117", 
								"59925ebaad13867dd9565118", "59925ecaad13867dd9565119", "59925eebad13867dd956511a", 
								"59925ef7ad13867dd956511b", "59925f06ad13867dd956511c", "59925f18ad13867dd956511d", 
								"59925f27ad13867dd956511e", "59925f57ad13867dd956511f", "59925f63ad13867dd9565120", 
								"599eb08cc819f5437a31b010", "59c344fae6d7da5458d9cd5a"];
					for (var i=0; i<20; i++) {
						if (idd == css[i]) return true;
					}
					return false;
				}

				for (var key in res.result){
					if (key == "photo"&&res.result.photo){
						$("#photo").attr("src",Core.id2url(res.result.photo));
						//添加背景图
						$("#cour_n").css("backgroundImage","url("+Core.id2url(res.result.photo)+")");
					}
					else if (key == "create"){
						$("#create").text((new Date(res.result.create)).pattern("yyyy-MM-dd HH:mm:ss"));
					}
					else if (key == "fee") {
						if (isNoFeeCourse(id)) {
							$("#" + key).html("  ");
						} else {
							$("#" + key).html(res.result[key]);
						}
					}
					else{	
						$("#" + key).html(res.result[key]);
					}
				}
				// add 课程介绍截取
				var num = $(".subzf").text();	
				num = num.substr(0,70);
				$(".subzf").text(num+"...");
				// end

				window.document.title = res.result.name+'-国开享学吧';
				$("#classHour").text(res.result.classHour);
				$("#cname").text(res.result.name);
				// .attr("href","a_indexMoreList.html?stype=course&ctypeid=" + res.result.ctype);
				$("#ctypeName").attr("href","a_indexMoreList.html?stype=course&ctypeid=" + res.result.ctype);
				var chapterList = '';
				// 改版
				for (var i = 0; i < res.result.chapter.length; i ++){
					chapterList +=	'<div class="cour_section shou">' + res.result.chapter[i].name + '<span class=" fr"></span></div><ul class="cour_li none">';
					for (var j = 0; j < res.result.chapter[i].knowledge.length; j ++){
						chapterList += '<li '+res.result.chapter[i].knowledge[j]._id+'>'+res.result.chapter[i].knowledge[j].name+'</li>';				
					}
					chapterList +='</ul>';
				}
				$(".chapList").append(chapterList);
				// 课程目录效果
				$(".cour_section").click(function(){
					$(this).toggleClass("backf5").siblings().removeClass("backf5");
					$(this).toggleClass("shou").siblings().removeClass("fang");
					$(this).toggleClass("fang").siblings().removeClass("shou");
					$(this).next(".cour_li").slideToggle(300).siblings(".cour_li").slideUp(500);
				});
				// 评论课程介绍切换
				$(".daP-title span").on("click",function(){
					var index = $(this).index();
					$(this).addClass('daP-bg').siblings().removeClass('daP-bg');
					$("#kengChenJiaoShao .box-pl").eq(index).show().siblings().hide();	
				});
				// 首项打开
				$(".chapList").find("div:eq(0)").addClass("fang backf5");
				$(".chapList").find("ul:eq(0)").removeClass("none")
				// end
				var teachersList = '<div class="daP-list-title">'+
								   '	<span >主讲教师</span>'+
								   '</div>';
				for (var i = 0; i < res.result.teachers.length; i ++){
					var img = 'img/t1.png';
					if (res.result.teachers[i].photo){
						img = Core.id2url(res.result.teachers[i].photo);
					}
					// 删除
					teachersList +=	'<div class="teachEvt cour-box" data-id="' + res.result.teachers[i]._id + '"> '+
									'	<div class="teacher">'+
									'		<div class="fl"><img src="' + img + '" ></div>'+
									'		<div class="fl">'+
									'			<p style="width:100px" class="ellipsis">' + res.result.teachers[i].name + '</p>'+
									'			<p>高级讲师</p>'+
									'		</div>'+
									'	</div>'+
									'	<div class="clear"></div>'+
									'	<div class="teacher-intro fs14" style="height:auto">'+
									'		<p>'+ res.result.teachers[i].des +'</p>'+							
									'	</div>'+
									'	<div style="border-bottom:1px solid #CCCCCC;margin:10px 20px"></div>'+
									'</div>	';
					if (i>=4) {
						break;
					}
				}
				$("#teachersList").append(teachersList);
				// $(".teachEvt").click(function(){
				// 	window.location.href = "a_indexDetailTeacher.html?stype=teacher&id=" + $(this).data("id");;
				// });

				// console.log(CurrentUser);
				if(CurrentUser.utype == 1000 && res.result.proAttr != 1){
					if(res.result._id == '56303cd299bf91651845f606' || res.result._id == '5608f28578748bd74f9959ea' || res.result._id == '5608f2ad78748bd74f9959eb'){
						$("#pay").html('<b class="parent" id="" style="background-color:#C5BEBE">购买课程</b>');
						$(".parent").parent("span").css("backgroundColor","#C5BEBE");
					}
					else{
						if (isNoFeeCourse(id)) {
							$("#pay").html('<b id="payBtn_NOT">购买课程</b>');
						} else {
							$("#pay").html('<b id="payBtn">购买课程</b>');
						}
					}
					$("#payBtn").click(function(){
						$("#lbtn").click();
					});
				}
				if(res.result.proAttr != 1){
					var flag = false;
					var flag1 = false;
					for(var i = 0; i < CurrentUser.course.length; i ++){
						if (CurrentUser.course[i].id == id){
							flag1 = true;
							if(CurrentUser.course[i].validity > 0)
								flag = true;
						}
					}
					if (flag || stype =="notvalue"){
						if(stype =="notvalue"){
							$("#pay").html('<b id="payBtn">续费课程</b>');
							$("#payBtn").click(function(){
								window.location.href = "a_indexStudentPay.html?cid="+res.result._id+"&fee="+res.result.fee+"&cname="+res.result.name+"&type=0&isRenew=0&validity="+res.result.validity+"&pType="+res.result.ctype;
								//IndexStudent.buyCourse(res.result._id, res.result.fee, res.result.name, );	
							});
						}else{
							$("#pay").html('<b id="payBtn">学习课程</b>');
							$("#payBtn").click(function(){
								window.location.href = "a_s_courseLearning.html?stype=course&id=" + id + "#newsL";	
							});
						}
					} 
					else {
						var isRenew = 1;
						var btnName = "购买课程";
						if(flag1){
							isRenew = 0;
							btnName = "续费课程";
						}
						if(res.result._id == '56303cd299bf91651845f606' || res.result._id == '5608f28578748bd74f9959ea' || res.result._id == '5608f2ad78748bd74f9959eb'){
							$("#pay").html('<b id="" class="parent" style="background-color:#C5BEBE">'+btnName+'</b>');
							$(".parent").parent("span").css("backgroundColor","#C5BEBE");
						}
						else{
							if (isNoFeeCourse(id)) {
								$("#pay").html('<b id="payBtn_NOT">'+btnName+'</b>');
							} else {
								$("#pay").html('<b id="payBtn">'+btnName+'</b>');
							}
						}
						$("#payBtn").click(function(){
							//to do..调用第三方付款
							if(res.result.proAttr != 1)//学历课程禁止购买
								window.location.href = "a_indexStudentPay.html?cid="+res.result._id+"&fee="+res.result.fee+"&cname="+res.result.name+"&type=0&isRenew="+isRenew+"&validity="+res.result.validity+"&pType="+res.result.ctype;
							else
								alert('学历课程，禁止购买！');
							//IndexStudent.buyCourse(res.result._id, res.result.fee, res.result.name);	
						});
					}
					if($.query.get("goto") == "1" && $("#payBtn").text() != "学习课程")
						$("#payBtn").click();
				}else
					$('.registration').html('<span><b>禁止购买</b></span><span></span>');
				if (CurrentUser.utype == UTYPE.TUTOR){
					$("#pay").html('<b id="payBtn">查看</b>');
					$("#payBtn").click(function(){
						window.location.href = "a_indexDetailCourse.html?stype=course&id=" + id + "#newsL";	
					});
				}

				//关联课程 添加
				var ctype = res.result.ctype;
				// console.log(ctype+"--"+id)
				$ajax({
					url:"/course/courseRecommend",
					data:{
						_id: id,
						ctype: ctype
					},
					success:function(res){
						var result = res.result;
						var tJian = "";
						// console.log(result.length);
						for(var i=0;i<result.length;i++){
							tJian+= '<div class="box_n addcour singleC" data-id="'+result[i]._id+'">'+
									'	<dl>'+
									'		<dt class="singleCa"><img src="upload/'+result[i].photo+'"></dt>'+
									'		<dd class="fs16 ellipsis singleCa" >'+result[i].name+'</dd>'+
									'		<dd class="c80 ellipsis" style="border-bottom: 1px solid #E6E6E6;">'+result[i].des+'</dd>'+
									'		<div class="addshouke">'+
									'			<span class="teach" style="width:40px;padding:0" data-tid="'+result[i].teachers[0].id+'"><img src="upload/'+result[i].teachers[0].photo+'"></span>'+
									'			<span style="padding-right:15px">授课老师：'+result[i].teachers[0].name+'</span>'+
									'			<span style="padding:0">认证学分：'+result[i].credit+'学分</span>'+
									'		</div>'+
									'	</dl>'+
									'</div>';
						}
						if(tJian.length <= 0){$(".recommend").hide();}
						$("#tuijan").html(tJian);
						$(".singleCa").click(function(){
							window.location.href = "a_indexDetailCourseFirst.html?stype=course&id=" + $(this).parents(".singleC").data("id");
						});
						// add teacher
						// $(".teach").click(function(){
						// 	window.location.href = "a_indexDetailTeacher.html?stype=teacher&id=" + $(this).data("tid");
						// });
					}
				});
				// end
			}
		})		
	},
	buyCertificate: function(certificateId){
		var userId = CurrentUser._id;
		var certificateId = certificateId;
		$.ajax({
			url : "https://www.yeepay.com/app-merchant-proxy/node",
			type: "get",
			success: function(res){
			}
		});
		$ajax({
			url : "/users/addCertificate",
			data : {
				userId: userId,
				certificateId: certificateId
			},
			success: function(res){
				alert("购买成功");
			}
		});
	},
	buyCourse: function(){
		// var pay = function(userId, courseId, ownerName, fee, courseName, isRenew, pType, payType){ //易宝支付构造函数
		// 	$ajax({
		// 		url : "/paylist/payCommit",
		// 		data : {
		// 			userId: userId,
		// 			courseId: courseId,
		// 			ownerName: ownerName,
		// 			fee: fee,
		// 			courseName: courseName,
		// 			payType: payType,
		// 			payTypeIsRenew: isRenew,
		// 			pType: pType
		// 		},
		// 		success: function(res){
		// 			var pMsg = res.result;
		// 			window.location.href = "https://www.yeepay.com/app-merchant-proxy/node?p3_Amt="+pMsg.p3_Amt+"&p2_Order="+ pMsg.p2_Order +"&p5_Pid="+pMsg.p5_Pid+"&p0_Cmd="+pMsg.p0_Cmd+"&p1_MerId="+pMsg.p1_MerId+"&keyValue="+pMsg.keyValue+"&p4_Cur="+pMsg.p4_Cur+"&p8_Url="+pMsg.p8_Url+"&pa_MP="+pMsg.pa_MP+"&hmac="+pMsg.hmac.toString();
		// 		}
		// 	});
		// }
		var pay = function(userId, courseId, ownerName, fee, courseName, isRenew, pType, payType,payPlatform){
			$ajax({
				url : "/paylist/payCommit",
				data : {
					userId: userId,
					courseId: courseId,
					ownerName: ownerName,
					fee: fee,
					courseName: courseName,
					payType: payType,
					payTypeIsRenew: isRenew,
					pType: pType,
					payPlatform: payPlatform,
					returnurl: 'a_indexStudy.html?buy=true'
				},
				success: function(res){
					window.open(res.result.url);
				}
			});
		}
		var PNAME = "课程名称";
		var payType = 0; //默认为购买课程  0：课程，1：证书
		if($.query.get('type')=="0"){
			$("#perfect").text("购买课程");
			name_ = "购买课程";
		}else{
			$("#perfect").text("报名取证");
			name_ = "报名取证";
			PNAME = "证书名称";
			payType = 1;
		}
		window.document.title = name_+'-国开享学吧';
		var userId = CurrentUser._id;
		var ownerName = CurrentUser.formalName;
		var courseId = $.query.get('cid');
		var fee = $.query.get('fee');
		var courseName = $.query.get('cname');
		var isRenew = ($.query.get('isRenew')=="0"?true:false);
		var validity = ($.query.get('validity')=="cer"?"":$.query.get('validity')+"天");
		var pType = $.query.get('pType');
		var html = '<tr>'+
				   '	<th>'+PNAME+'</th>'+
				   '	<th>有效期</th>'+
				   '	<th>费用</th>'+
				   '	<th>操作</th>'+
				   '</tr>'+
				   '<tr>'+
				   '	<td>'+courseName+'</td>'+
				   '	<td>'+validity+'</td>'+
				   '	<td>'+fee+'元</td>'+
				   '	<td><button class="btn btn-danger btn-sm zhiF_btn">缴费</button></td>'+
				   '</tr>';
		$(".zhiF_table").html(html);
		$(".zhiF_btn").click(function(){
			//pay(userId, courseId, ownerName, fee, courseName, isRenew, pType, $.query.get('type'));//易宝调用
			pay(userId, courseId, ownerName, fee, courseName, isRenew, pType, payType,'alipay');
		})
	},
	//申请证书js
	applyCertificateInit: function(){
		// 申请证书stype=1:国开，stype=2：非
		var certificate = $.query.get('cer');
		var cer = certificate.split(',');
		var stype = cer[0];
		var cerId = cer[1];
		var ctype = cer[2];
		var cerName = cer[3];
		var applyfee = cer[4];
		var cerOrganization = cer[5];
		var yesApplyfee = cer[6];
		var certifiStatus = cer[7];
		var userId = CurrentUser._id;
		if(applyfee == "" ||applyfee == "undefined")
			applyfee = 0;
		$("#mpassword").focus();
		var rej = $.query.get('rej');
		if(rej == "refuse"){
			$(".jvJueX").removeClass("hidden");
			$ajax({
				url: "/users/findCertificateInfo",
				data: {
					id: CurrentUser._id,
					cerId: cerId
				},
				success: function(res){
					eCert1 = res.result.eCert;//判断是否为1，为1则为电子的
					PaperCertificate1 = res.result.PaperCertificate;//判断是否为1，为1则为纸质
					if(eCert1 == undefined)
						SetLS("ele", "undefined");
					if(PaperCertificate1 ==undefined)
						SetLS("pap", "undefined");
					$("#yanPwd").hide();
					$("#Detail").show();
					if(res.result.express !=undefined){
						$("#peoName").val(res.result.express.peoName);
						$("#peoPhone").val(res.result.express.peoPhone);
						$("#peoAddress").val(res.result.express.addr);
						$("#peoZipCode").val(res.result.express.peoZipCode);
						var src = Core.id2url(res.result.userPhoto);
			    		$("#photoC").html('<img style="width:183px;height:254px" src="' + src + '">');   
						$("#photoBtn").attr("data-url",res.result.userPhoto);
						$("#rej").text(res.result.rejectDes);
					}
				}
			});
		}else{
			//if(CurrentUser.features.registerType !=2){//助力计划的学员申请证书时不用验证密码
				$("#yanPwd").show();
				$(".yan_btn").click(function(){
					var npwm = $("#mpassword").val();
					var pwd = CryptoJS.AES.decrypt(CurrentUser.password, "gkonlearning").toString(CryptoJS.enc.Utf8);
					if ( npwm != pwd){
						return $(".error_g").removeClass("hidden");
					}else{
						$("#yanPwd").hide();
						$("#Detail").show();
					}
				});
			//}
		}
		$("#photoBtn").uploadify({
		    'swf'        : 'js/core/uploadify.swf',
		    'uploader'   :  Core.API_VER+"/upload?compress=0",
		    'buttonText' : '上传图片',
		    'method':"post",
		    'fileTypeDesc': '请选择图片格式', 
		    'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.swf',
		    'fileSizeLimit'   : '3072',
		    'onUploadSuccess' : function(file, res) {
		        res = eval('(' + res + ')');
		        if (res.code) {
		    		$alert(res.codemsg);
		    		return;
		    	}	                 
		        var url = res.result.url;	
		    	$("#photoBtn").attr("data-url",url);
		    	var src = Core.id2url(url);
		    	$("#photoC").html('<img style="width:183px;height:254px" src="' + src + '">');                      
		    },
		    'onUploadStart' : function(file) {
		                         
		    } 
		});
		$("#photoBtn").change(IndexStudent.userPhotoupload);
		//alert(src);
		//console.log(CurrentUser);
		for(var key in CurrentUser){//库里有的值显示在列表中
			$("#" + key).val(CurrentUser[key]);
			//用户证书上显示的图片
			for(var ll=0; ll<CurrentUser.certificate.length; ll++){
				if(CurrentUser.certificate[ll].id == cerId){
					var src = '/img/tou2.jpg';
					if('photo' in CurrentUser){//判定用户 头像字段 是否存在
						if(CurrentUser.photo != '' && CurrentUser.photo != null && CurrentUser.photo != undefined){
							if(CurrentUser.photo.indexOf('upload') > 0)
								src = CurrentUser.photo;
							else
								src = Core.id2url(CurrentUser.photo);
						}
					}
					if('userPhoto' in CurrentUser.certificate[ll]){
						//存在userPhoto字段
						if(CurrentUser.certificate[ll].userPhoto != '' && CurrentUser.certificate[ll].userPhoto != undefined && CurrentUser.certificate[ll].userPhoto != null){
							//userPhoto字段 不为空
							var uphoto = CurrentUser.certificate[ll].userPhoto;
							if(uphoto.indexOf('upload') > 0)
								src = uphoto;
							else
								src = Core.id2url(uphoto);
							$("#photoC").html('<img style="width:183px;height:254px" src="' + src + '">');
							$("#photoBtn").attr("data-url",uphoto);
						}
						else{
							//userPhoto 为空
							$("#photoC").html('<img style="width:183px;height:254px" src="' + src + '">');
							$("#photoBtn").attr("data-url",uphoto);
						}
					}else{
						$("#photoC").html('<img style="width:183px;height:254px" src="' + src + '">');
						$("#photoBtn").attr("data-url",uphoto);
					}
					
				}
			}
			//性别判定
			if(key == "sex"){
				if( CurrentUser[key] !=  undefined){
					if(CurrentUser[key].substring(0,1) == '男')
						$('#sex').get(0).selectedIndex=1;
					else
						$('#sex').get(0).selectedIndex=2;
				}
			}
			
		}
		//拒绝后的证书不显示第四步
		// if(certifiStatus ==4){
		// 	$("#x5,#x4,#x3,#x2,#x1").addClass('hidden');
		// 	$("#k5,#k4,#k3,#k2,#k1").addClass('hidden');
		// }
		//声明保存时的变量名
			var subscard = "";
			var subformalName = "";
			var subsex = "";
			var subphone = "";
			var userPhoto = "";

			var subpeoName = "";
			var subpeoPhone = "";
			var subpeoAddress = "";
			var subpeoZipCode = "";
			var subexpMoney = 0;
			var subcarMoney = 0;
			var subsumMoney = 0;

		//判定 是否有真实姓名和身份证号
		var scard = $("#scard").val();
		var formalName = $("#formalName").val();
		if(formalName == ""){
				$('#formalName').removeAttr("disabled"); 
			}
			if(scard ==""){
				$('#scard').removeAttr("disabled"); 
			}
		//基本信息没有填写“下一步”不可用
		var scardf = false;
		var formalNamef = false;
		var sexf = false;
		var phonef = false;
		var companyf =false;
		var formalName = $("#formalName").val();
			if(formalName.length>=1 && $.trim(formalName) != '')
				formalNamef = true;
		var scard = $("#scard").val();
			if(scard.length>=1 && $.trim(scard) != '')
				scardf = true;
		var sex = $("#sex option:selected").val();
			if(sex.length>=1 && $.trim(sex) != '')
				sexf = true;
		var phone = $("#phone").val();
			if(phone.length>=1 && $.trim(phone) != '')
				phonef = true;
		var company = $("#company").val();
			if(company.length>=1 && $.trim(company) != '')
				companyf = true;

		if($("#formalName").val().length>=1 && $("#scard").val().length>=1 && $("#phone").val().length>=1 && $("#company").val().length>=1 && $("#company").val().length>=1 ){
			$(".nextOne").removeClass('z_bgC');
		}

		$("#formalName").change(function(){
			var formalName = $("#formalName").val();
			if(formalName.length>=1 && $.trim(formalName) != '')
				formalNamef = true;
		});
		$("#scard").change(function(){
			var scard = $("#scard").val();
			if(scard.length>=1 && $.trim(scard) != '')
				scardf = true;
		});
		$("#sex").change(function(){
			var sex = $("#sex option:selected").val();
			if(sex.length>=1 && $.trim(sex) != '')
				sexf = true;
		});
		$("#phone").change(function(){
			var phone = $("#phone").val();
			if(phone.length>=1 && $.trim(phone) != '')
				phonef = true;
		});
		$("#company").change(function(){
			var company = $("#company").val();
			if(company.length>=1 && $.trim(company) != '')
				companyf = true;
		});

		//失去焦点判断所有输入框 
		$("#formalName").blur(function(){
			if(formalNamef && scardf && sexf && phonef && companyf)
				$(".nextOne").removeClass('z_bgC');
		});
		$("#scard").blur(function(){
			if(formalNamef && scardf && sexf && phonef && companyf)
				$(".nextOne").removeClass('z_bgC');
		});
		$("#sex").blur(function(){
			if(formalNamef && scardf && sexf && phonef && companyf)
				$(".nextOne").removeClass('z_bgC');
		});
		$("#phone").blur(function(){
			if(formalNamef && scardf && sexf && phonef && companyf)
				$(".nextOne").removeClass('z_bgC');
		});
		$("#company").blur(function(){
			if(formalNamef && scardf && sexf && phonef && companyf)
				$(".nextOne").removeClass('z_bgC');
		});
		$(".nextOne").click(function(){
			var scard = $("#scard").val();
			var formalName = $("#formalName").val();
			var sex = $("#sex").val();
			var phone = $("#phone").val();
			var photo = $("#photoBtn").attr("data-url");
			//身份证号码判定
			if(scard !="") {
				if(!checkIDNum($("#scard").val()))//验证身份证号
					return;
			}else{
				$("#scard").focus();
				return alert("提示\n\n请将身份证号码补充完整！");
			}
			//电话判定
			if(phone !="") {
				if(!checkPhone($("#phone").val()))
					return;
			}else{
				$("#phone").focus();
				return alert("提示\n\n请输入手机号码！");
			}
			//非空判定
			if(formalName =="" && $.trim(formalName) != ''){
				return alert("提示\n\n请将姓名补充完整！");
			}else if(sex =="" && $.trim(sex) != ''){
				return alert("提示\n\n请将性别补充完整！");
			}else if(photo == undefined){
				return alert("提示\n\n请上传您证书上的照片！");
			}
			
			//颁证机构1:国开2非,1有选择是否申请纸质 跳过类型 2显示类型 跳过选择
			if(certifiStatus == 4 && stype==1){//申请被拒绝
				if(GetLS("pap") !=undefined || typeof(GetLS("pap")) != "undefined"){
					if(GetLS("pap") ==1){
						//纸质且支付成功
						$("#messSure").addClass('hidden');
						$("#cerType").removeClass('hidden');
						var cerType = "您已经申请《"+ cerName +"》的纸质版，由"+ cerOrganization +"审核，并颁发。";
						$("#cerTypeDetail").text(cerType);
					}else{
						//未支付
						$("#messSure").addClass('hidden');
						$("#cerType").removeClass('hidden');
						var cerType = "您已经申请《"+ cerName +"》的纸质版，由"+ cerOrganization +"审核，并颁发。";
						$("#cerTypeDetail").text(cerType);
					}
				}else if(GetLS('ele') != undefined && GetLS('ele') ==1){
					//电子版 列出选择给出第四步
					var paperCer = "《"+ cerName +"》可选择是否申请纸质证书，如果暂时不申请纸质证书，我们仅为您提供电子证书。";
					$("#paperDetail").text(paperCer);
					$("#messSure").addClass('hidden');
					$("#paperCer").removeClass('hidden');

					$("#f").change(function(){
						$("#show_").removeClass('z_bgC');
						$("#papernNext").addClass('z_bgC');
					});
					$("#s").change(function(){
						$("#show_").addClass('z_bgC');
						$("#papernNext").removeClass('z_bgC');
					});
					$(".nextThree").click(function(){
						$("#paperCer").addClass('hidden');
						$("#expMessage").removeClass('hidden');
						if($("#peoName").val() !="" && $("#peoPhone").val() !="" && $("#peoAddress").val()!="" && $("#peoZipCode").val()!="" ){
							if(certifiStatus == 4){
								$(".nextFour").text('保存并提交');
								subpeoName = $("#peoName").val();
								subpeoPhone = $("#peoPhone").val();
								subpeoAddress = $("#peoAddress").val();
								subpeoZipCode = $("#peoZipCode").val();
								$("#nextFour").click(function(){
									$('#show_').click();
								});
							}
							$(".nextFour").removeClass('z_bgC');
						}
						//处理点击头部显示问题
						$("#n1,#n2,#n3,#n4,#n5").click(function(){
							$("#messSure").removeClass('hidden');
							$("#cerType").addClass('hidden');
							$("#paperCer").addClass('hidden');
							$("#expMessage").addClass('hidden');
							$("#costMoney").addClass('hidden');
						});
						$("#m1,#m2,#m3,#m4,#m5").click(function(){
							if(certifiStatus == 4){
								if(stype ==1 && GetLS("ele") ==1){
									$("#paperCer").removeClass('hidden');
									$("#cerType").addClass('hidden');
								}
								else{
									$("#cerType").removeClass('hidden');
									$("#paperCer").addClass('hidden');
								}
							}else {
								if(stype ==1){
									$("#paperCer").removeClass('hidden');
									$("#cerType").addClass('hidden');
								}
								else{
									$("#cerType").removeClass('hidden');
									$("#paperCer").addClass('hidden');
								}
							}
							$("#messSure").addClass('hidden');
							$("#expMessage").addClass('hidden');
							$("#costMoney").addClass('hidden');
						});
						$("#z1,#z2,#z3,#z4,#z5").click(function(){
							$("#expMessage").removeClass('hidden');
							$("#cerType").addClass('hidden');
							$("#paperCer").addClass('hidden');
							$("#messSure").addClass('hidden');
							$("#costMoney").addClass('hidden');
						});
						$("#x1,#x2,#x3,#x4,#x5").click(function(){
							$("#costMoney").removeClass('hidden');
							$("#cerType").addClass('hidden');
							$("#paperCer").addClass('hidden');
							$("#expMessage").addClass('hidden');
							$("#messSure").addClass('hidden');
						});
					});
				}
							
			}else{//第一次申请
				if(stype==1){
					$("#messSure").addClass('hidden');
					$("#paperCer").removeClass('hidden');
					$("#f").change(function(){
						$("#show_").removeClass('z_bgC');
						$("#papernNext").addClass('z_bgC');
					});
					$("#s").change(function(){
						$("#show_").addClass('z_bgC');
						$("#papernNext").removeClass('z_bgC');
					});
					$(".nextThree").click(function(){
						$("#paperCer").addClass('hidden');
						$("#expMessage").removeClass('hidden');
						if($("#peoName").val() !="" && $("#peoPhone").val() !="" && $("#peoAddress").val()!="" && $("#peoZipCode").val()!="" ){
							if(certifiStatus == 4){
								$(".nextFour").text('保存并提交');
								subpeoName = $("#peoName").val();
								subpeoPhone = $("#peoPhone").val();
								subpeoAddress = $("#peoAddress").val();
								subpeoZipCode = $("#peoZipCode").val();
								$("#nextFour").click(function(){
									$('#show_').click();
								});
							}
							$(".nextFour").removeClass('z_bgC');
						}
						//处理点击头部显示问题
						$("#n1,#n2,#n3,#n4,#n5").click(function(){
							$("#messSure").removeClass('hidden');
							$("#cerType").addClass('hidden');
							$("#paperCer").addClass('hidden');
							$("#expMessage").addClass('hidden');
							$("#costMoney").addClass('hidden');
						});
						$("#m1,#m2,#m3,#m4,#m5").click(function(){
							if(certifiStatus == 4){
								if(stype ==1 && GetLS("ele") ==1){
									$("#paperCer").removeClass('hidden');
									$("#cerType").addClass('hidden');
								}
								else{
									$("#cerType").removeClass('hidden');
									$("#paperCer").addClass('hidden');
								}
							}else {
								if(stype ==1 ){
									$("#paperCer").removeClass('hidden');
									$("#cerType").addClass('hidden');
								}
								else{
									$("#cerType").removeClass('hidden');
									$("#paperCer").addClass('hidden');
								}
							}
							$("#messSure").addClass('hidden');
							$("#expMessage").addClass('hidden');
							$("#costMoney").addClass('hidden');
						});
						$("#z1,#z2,#z3,#z4,#z5").click(function(){
							$("#expMessage").removeClass('hidden');
							$("#cerType").addClass('hidden');
							$("#paperCer").addClass('hidden');
							$("#messSure").addClass('hidden');
							$("#costMoney").addClass('hidden');
						});
						$("#x1,#x2,#x3,#x4,#x5").click(function(){
							$("#costMoney").removeClass('hidden');
							$("#cerType").addClass('hidden');
							$("#paperCer").addClass('hidden');
							$("#expMessage").addClass('hidden');
							$("#messSure").addClass('hidden');
						});
					});
				}else{
					$("#messSure").addClass('hidden');
					$("#cerType").removeClass('hidden');
					
				}
			}
			
			//保存基本信息
			subscard = $("#scard").val();
			subformalName = $("#formalName").val();
			subsex = $("#sex").val();
			subphone = $("#phone").val();
			userPhoto = $("#photoBtn").attr("data-url");
			//处理点击头部显示问题
			$("#n1,#n2,#n3,#n4,#n5").click(function(){
				$("#messSure").removeClass('hidden');
				$("#cerType").addClass('hidden');
				$("#paperCer").addClass('hidden');
				$("#expMessage").addClass('hidden');
				$("#costMoney").addClass('hidden');
			});
			$("#m1,#m2,#m3,#m4,#m5").click(function(){
				if(certifiStatus == 4){
					if(stype ==1 && GetLS("ele") ==1){
						$("#paperCer").removeClass('hidden');
						$("#cerType").addClass('hidden');
					}
					else{
						$("#cerType").removeClass('hidden');
						$("#paperCer").addClass('hidden');
					}
				}else {
					if(stype ==1){
						$("#paperCer").removeClass('hidden');
						$("#cerType").addClass('hidden');
					}
					else{
						$("#cerType").removeClass('hidden');
						$("#paperCer").addClass('hidden');
					}
				}
				$("#messSure").addClass('hidden');
				$("#expMessage").addClass('hidden');
				$("#costMoney").addClass('hidden');
			});
			
		});
		//证书类型中颁证机构等说明文字
		if(certifiStatus != 4){//第一次申请的时候走
			if(stype ==1){
				var paperCer = "《"+ cerName +"》可选择是否申请纸质证书，如果暂时不申请纸质证书，我们仅为您提供电子证书。";
				$("#paperDetail").text(paperCer);
			}else{
				var cerType = "《"+ cerName +"》由"+ cerOrganization +"审核，并颁发纸质证书。";
				$("#cerTypeDetail").text(cerType);
			}
		}else if(certifiStatus == 4 && (GetLS('pap') ==1)){
				var cerType = "您已经申请《"+ cerName +"》的纸质版，由"+ cerOrganization +"审核，并颁发。";
				$("#cerTypeDetail").text(cerType);
		}else if(certifiStatus == 4 && (GetLS('ele') ==1)){
				//var cerType = "您已经申请《"+ cerName +"》的纸质版，由"+ cerOrganization +"审核，并颁发。";
				//$("#cerTypeDetail").text(cerType);
				$("#paperCer").removeClass("hidden");
				$("#cerType").addClass("hidden");
				console.log('dainzizhenshu');
		}else if(stype ==2){
			var cerType = "《"+ cerName +"》由"+ cerOrganization +"审核，并颁发纸质证书。";
				$("#cerTypeDetail").text(cerType);
		}
		//纸质证书部分
		$(".nextTwo").click(function(){
			$("#cerType").addClass('hidden');
			$("#expMessage").removeClass('hidden');
			if($("#peoName").val() !="" && $("#peoPhone").val() !="" && $("#peoAddress").val()!="" && $("#peoZipCode").val()!="" ){
				if(certifiStatus == 4){
					//return alert('123');
					$(".nextFour").text('保存并提交');
					subpeoName = $("#peoName").val();
					subpeoPhone = $("#peoPhone").val();
					subpeoAddress = $("#peoAddress").val();
					subpeoZipCode = $("#peoZipCode").val();
					$("#nextFour").click(function(){
						$('#show_').click();
					});
				}
				$(".nextFour").removeClass('z_bgC');
			}
			//处理点击头部显示问题
			$("#n1,#n2,#n3,#n4,#n5").click(function(){
				$("#messSure").removeClass('hidden');
				$("#cerType").addClass('hidden');
				$("#paperCer").addClass('hidden');
				$("#expMessage").addClass('hidden');
				$("#costMoney").addClass('hidden');
			});
			$("#m1,#m2,#m3,#m4,#m5").click(function(){
				if(certifiStatus == 4){
					if(stype ==1 && GetLS("ele") ==1){
						$("#paperCer").removeClass('hidden');
						$("#cerType").addClass('hidden');
					}
					else{
						$("#cerType").removeClass('hidden');
						$("#paperCer").addClass('hidden');
					}
				}else {
					if(stype ==1){
						$("#paperCer").removeClass('hidden');
						$("#cerType").addClass('hidden');
					}
					else{
						$("#cerType").removeClass('hidden');
						$("#paperCer").addClass('hidden');
					}
				}
				$("#messSure").addClass('hidden');
				$("#expMessage").addClass('hidden');
				$("#costMoney").addClass('hidden');
			});
			$("#z1,#z2,#z3,#z4,#z5").click(function(){
				$("#expMessage").removeClass('hidden');
				$("#cerType").addClass('hidden');
				$("#paperCer").addClass('hidden');
				$("#messSure").addClass('hidden');
				$("#costMoney").addClass('hidden');
			});
			
		});
		//邮寄信息部分
		var peoNamef = false;
		var peoPhonef = false;
		var peoAddressf = false;
		var peoZipCodef = false;
		//输入框值改变判定是否为空和去掉空格后判定
		$("#peoName").change(function(){
			var peoName = $("#peoName").val();
			if(peoName.length>=1 && $.trim(peoName) != '')
				peoNamef = true;
		});
		$("#peoPhone").change(function(){
			var peoPhone = $("#peoPhone").val();
			if(peoPhone.length>=1 && $.trim(peoPhone) != '')
				peoPhonef = true;
		});
		$("#peoAddress").change(function(){
			var peoAddress = $("#peoAddress").val();
			if(peoAddress.length>=1 && $.trim(peoAddress) != '')
				peoAddressf = true;
		});
		$("#peoZipCode").change(function(){
			var peoZipCode = $("#peoZipCode").val();
			if(peoZipCode.length>=1 && $.trim(peoZipCode) != '')
				peoZipCodef = true;
		});
		//所有输入框 失去焦点 判定
		$("#peoName").blur(function(){
			if(peoNamef && peoPhonef && peoAddressf && peoZipCodef)
				$(".nextFour").removeClass('z_bgC');
		});
		$("#peoPhone").blur(function(){
			if(peoNamef && peoPhonef && peoAddressf && peoZipCodef)
				$(".nextFour").removeClass('z_bgC');
		});
		$("#peoAddress").blur(function(){
			if(peoNamef && peoPhonef && peoAddressf && peoZipCodef)
				$(".nextFour").removeClass('z_bgC');
		});
		$("#peoZipCode").blur(function(){
			if(peoNamef && peoPhonef && peoAddressf && peoZipCodef)
				$(".nextFour").removeClass('z_bgC');
		});

		$(".nextFour").click(function(){
			// if(certifiStatus == 4){
			// 	$('#show_').click();
			// }else{
				var peoName = $("#peoName").val();
				var peoPhone = $("#peoPhone").val();
				var peoAddress = $("#peoAddress").val();
				var peoZipCode = $("#peoZipCode").val();
				//非空判定
				if(peoName == "" || peoAddress == ""){
					return alert("提示\n\n请将邮递信息补充完整！");
				}
				//电话判定
				if(peoPhone !="") {
					if(!checkPhone($("#peoPhone").val()))
						return;
				}else{
					$("#peoPhone").focus();
					return alert("提示\n\n请输入的收件人手机号码！");
				}
				//邮政编码判定
				if(peoZipCode != "") {
					if(!checkZipCode($("#peoZipCode").val()))
						return;
				}else{
					$("#peoZipCode").focus();
					return alert("提示\n\n请输入的邮递地址的邮政编码！");
				}

				//判定结束显示下一个页面
				$("#expMessage").addClass('hidden');
				$("#costMoney").removeClass('hidden');
				//保存邮寄信息
				subpeoName = $("#peoName").val();
				subpeoPhone = $("#peoPhone").val();
				subpeoAddress = $("#peoAddress").val();
				subpeoZipCode = $("#peoZipCode").val();
			//}
		});
		
		//支付费用部分
		var zhulifee = 1;
		var thisId = cerId;
		for(var ll=0; ll<CurrentUser.certificate.length; ll++){
			if(CurrentUser.certificate[ll].id == thisId && CurrentUser.certificate[ll].PaperCertificate ==0){
				zhulifee =0;
			}
		}
		var expMoney = 10;//快递费用
		if(certifiStatus == 4)//被拒绝的学员 重新申请证书不用缴纳快递费用
			expMoney = 0;
		var carMoney = 0 ;
		if((CurrentUser.features.registerType ==2 && zhulifee ==0) )
			carMoney = applyfee;//单独申请证书费用 =2是助力计划的学员申请只付证书单独申请的费用
		else
			$("#moneyLi").addClass('hidden');
		var sumMoney =( Number(expMoney) + Number(carMoney));
		$("#expMoney").text(expMoney);
		$("#carMoney").text(carMoney);
		$("#sumMoney").text(sumMoney);
		$(".subAll").click(function(){
			subexpMoney = expMoney;
			subcarMoney = carMoney;
			subsumMoney = sumMoney;
		});
		//选择纸质付费
		$("#show_1").click(function(){
			var showText = "一旦提交信息将无法修改，确认提交并支付？";
			$(".queRen").html(showText);
			$(".t_sub").addClass("fee");
				$(".fee").click(function(){
					if(certifiStatus ==  1){
						$ajax({
							url : "/paylist/payCer",
							data : {
							"cer":{
									"id": userId,
									"cerId": cerId,
									"pType": ctype,
									"cerName": cerName,
									"formalName": subformalName,
									"fee":subsumMoney,
									"scard": subscard,
									"sex": subsex,
									"phone": subphone,
									"company": $("#company").val(),
									"userPhoto": userPhoto,
									"addr": subpeoAddress,
									"peoName": subpeoName,
									"peoPhone": subpeoPhone,
									"peoZipCode": subpeoZipCode
								}
							},
							success: function(res){
								var pMsg = res.result;
								locaHref("https://www.yeepay.com/app-merchant-proxy/node?p2_Order="+pMsg.p2_Order+"&p3_Amt="+pMsg.p3_Amt+"&p5_Pid="+pMsg.p5_Pid+"&p0_Cmd="+pMsg.p0_Cmd+"&p1_MerId="+pMsg.p1_MerId+"&keyValue="+pMsg.keyValue+"&p4_Cur="+pMsg.p4_Cur+"&p8_Url="+pMsg.p8_Url+"&pa_MP="+pMsg.pa_MP+"&hmac="+pMsg.hmac.toString());
							}
						});
					}else if(certifiStatus ==  4){
						$ajax({
							url: "/users/saveCertificateStatus",
							data:{
								id: CurrentUser._id,
								cerId: cerId,
								cerStatus: 2 //审核中
							},
							success: function(res) {
								locaHref("a_indexStudy.html?" + random() + "#myCourseList");
							}
						});
					}else
						console.log('学员证书状态不正确：'+certifiStatus);
				});
		});
		
		//不选择纸质证书
		$('#show_').click(function(){
			var showText = "请最终确认相关信息，否则提交之后将不能修改!"
			$(".queRen").html(showText);
			$(".t_sub").addClass('nofee');
				$(".nofee").click(function(){
					$ajax({
						url : "/users/saveCertificateExpress",
						data: {
							id: userId,
							cerId: cerId,
							cerName: cerName,
							eCert: 1,
							pType: ctype,
							formalName: subformalName,
							scard: subscard,
							sex: subsex,
							phone: subphone,
							company: $("#company").val(),
							userPhoto: userPhoto,
							addr: subpeoAddress,
							peoName: subpeoName,
							peoPhone: subpeoPhone,
							peoZipCode: subpeoZipCode
						},
						success: function(res){
							locaHref("a_indexStudyApplySubmit.html?id="+$.query.get("id"));
						}
					});
				});
		});
		//处理点击头部显示问题
		// $("#n1,#n2,#n3,#n4,#n5").click(function(){
		// 	$("#messSure").removeClass('hidden');
		// 	$("#cerType").addClass('hidden');
		// 	$("#paperCer").addClass('hidden');
		// 	$("#expMessage").addClass('hidden');
		// 	$("#costMoney").addClass('hidden');
		// });
		// $("#m1,#m2,#m3,#m4,#m5").click(function(){
		// 	if(stype ==1)
		// 		$("#paperCer").removeClass('hidden');
		// 	else
		// 		$("#cerType").removeClass('hidden');
		// 	$("#messSure").addClass('hidden');
		// 	$("#expMessage").addClass('hidden');
		// 	$("#costMoney").addClass('hidden');
		// });
		// $("#z1,#z2,#z3,#z4,#z5").click(function(){
		// 	$("#expMessage").removeClass('hidden');
		// 	$("#cerType").addClass('hidden');
		// 	$("#paperCer").addClass('hidden');
		// 	$("#messSure").addClass('hidden');
		// 	$("#costMoney").addClass('hidden');
		// });
		// $("#x1,#x2,#x3,#x4,#x5").click(function(){
		// 	$("#costMoney").removeClass('hidden');
		// 	$("#cerType").addClass('hidden');
		// 	$("#paperCer").addClass('hidden');
		// 	$("#expMessage").addClass('hidden');
		// 	$("#messSure").addClass('hidden');
		// });
		// $("#pertSubmit").click(function(){
		// 	var cerid = $.query.get('id');

		// 	var scard = $("#scard").val();//
		// 	var formalName = $("#formalName").val();//
		// 	var sex = $("#sex").val();//
		// 	var phone = $("#phone").val();//
		// 	var education = $("#education").val();
		// 	var company = $("#company").val();
		// 	var address = $("#address").val();//
		// 	var zipCode = $("#zipCode").val();//

		// 	var peoName = $("#peoName").val();//
		// 	var peoPhone = $("#peoPhone").val();//
		// 	var peoAddress = $("#peoAddress").val();//
		// 	var peoZipCode = $("#peoZipCode").val();//
		// 	$ajax({
		// 		url : "/users/saveCertificateExpress",
		// 		data: {
		// 			id: CurrentUser._id,
		// 			cerId: cerid,
		// 			scard: scard,
		// 			formalName: formalName,
		// 			sex: sex,
		// 			phone: phone,
		// 			education: education,
		// 			company: company,
		// 			address: address,
		// 			zipCode: zipCode,

		// 			addr: peoAddress,
		// 			userPhoto: $("#photoBtn").attr("data-url"),
		// 			peoName: peoName,
		// 			peoPhone: peoPhone,
		// 			peoZipCode: peoZipCode
		// 		},
		// 		success: function(res){
		// 			window.location.href = "a_indexStudyApplySubmit.html?id="+$.query.get("id");
		// 		}
		// 	});
		// });
		//$("#modiPassSubmit").click(IndexStudent.modiPassSubmit);
	},
	userPhotoupload: function(){
		$("#photoForm").ajaxSubmit({
	        url: Core.API_VER+"/upload?compress=0",
	        type: "post",
	        success: function (res, textStatus) {
	        	//res = JSON.parse(res);
	        	if (res.code) {
	        		$alert(res.codemsg);
	        		return;
	        	}	        
	        	var url = res.result.url;	
	        	$("#photoBtn").attr("data-url",url);
	        	var src = Core.id2url(url);
	        	$("#photoD").html('<img style="width:183px;" src="' + src + '">');
	        },error:function(XMLHttpRequest, textStatus){
				var status = XMLHttpRequest.status;
				if (status == 0)
					return;
				else if (status == 500)
					$alert("服务器错误");
				else
					$alert("请检查您的网络。");
	        }
	    });
	},
	applyCertificateSubmit: function(){
		var cerid = $.query.get('id');
		var npwm = $("#mpassword").val();
		var scard = $("#scard").val();
		var peoName = $("#peoName").val();
		var peoPhone = $("#peoPhone").val();
		var peoAddress = $("#peoAddress").val();
		var peoZipCode = $("#peoZipCode").val();
		var pwd = CryptoJS.AES.decrypt(CurrentUser.password, "gkonlearning").toString(CryptoJS.enc.Utf8);
		console.log(CurrentUser);
		if ( npwm != pwd)
			return alert("密码有误,身份校验未通过")

		$ajax({
			url : "/users/saveCertificateExpress",
			data: {
				id: CurrentUser._id,
				cerId: cerid,
				formalName: CurrentUser.name,
				scard: scard,
				addr: peoAddress,
				userPhoto: $("#photoBtn").attr("data-url"),
				peoName: peoName,
				peoPhone: peoPhone,
				peoZipCode: peoZipCode
			},
			success: function(res){
				window.location.href = "a_indexStudyApplySubmit.html";
			}
		});
	},
	//完善资料js函数
	bc: function(){
			if($("#name").val() =="" || $("#scard").val() =="" ){
				$(".queRen").text("姓名或身份证号还未填写，确认保存？");
			}else{
				$(".queRen").text("保存后姓名和身份证号将不能修改，确认保存？");
			}
			$("body,html").animate({scrollTop:0},0);
			$('.tan_x').show();
			$('.tan_x').height($(document).height());
			$('#tan_all').slideDown(200);
	},
	permodipasswordInit: function(){
		var url = window.location.href;
		if(url.split("#")[1] == "pert"){
			$(".widFixed").show();
			$("#pert").hide();
			$("#mpassword").focus(function(){
				$(".error_g").addClass("hidden");
			})
			$(".yan_btn").click(function(){
				var npwm = $("#mpassword").val();
				var pwd = CryptoJS.AES.decrypt(CurrentUser.password, "gkonlearning").toString(CryptoJS.enc.Utf8);
				if ( npwm != pwd){
					return $(".error_g").removeClass("hidden");
				}
				else{
					$(".widFixed").hide();
					$("#pert").show();
				}
			});
		}else{
			$(".widFixed").hide();
		}
		$("#photoBtn").uploadify({
		    'swf'        : 'js/core/uploadify.swf',
		    'uploader'   :  Core.API_VER+"/upload?compress=0",
		    'buttonText' : '上传图片',
		    'method':"post",
		    'fileTypeDesc': '请选择图片格式', 
		    'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.swf',
		    'fileSizeLimit'   : '3072',
		    'onUploadSuccess' : function(file, res) {
		        res = eval('(' + res + ')');
		        if (res.code) {
		    		$alert(res.codemsg);
		    		return;
		    	}	                 
		        var url = res.result.url;	
		    	$("#photoBtn").attr("data-url",url);
		    	var src = Core.id2url(url);
		    	$("#photoD").html('<img style="width:183px;" src="' + src + '">');                      
		    },
		    'onUploadStart' : function(file) {
		                         
		    } 
		});
		for(var key in CurrentUser){
			$("#" + key).val(CurrentUser[key]);
			if(key == "formalName"){
				if(CurrentUser.formalName || CurrentUser.formalName != ""){
					$("#formalName").attr("disabled", "disabled");
				}
			}
			if(key == "scard"){
				if(CurrentUser.scard || CurrentUser.scard != "")
					$("#scard").attr("disabled", "disabled");
			}
			var src = "img/tou1.jpg";
			if (key == "photo"){
				src = Core.id2url(CurrentUser[key]);
				$("#photoD").html('<img style="width:183px;" src="' + src + '">');
				$("#photoBtn").attr("data-url",CurrentUser[key]);
			}
			if(key == "sex"){
				if( CurrentUser[key] !=  undefined){
					if(CurrentUser[key].substring(0,1) == '男')
						$('#sex').get(0).selectedIndex=1;
					else
						$('#sex').get(0).selectedIndex=2;
				}
			}
		}
		$('#baoC_g').bind("click", IndexStudent.bc);
		$('.tan-poptit .close,#cancel').click(function(){
			$('.tan_x').hide();
			$('#tan_all').slideUp(200);
		})
		$("#photoBtn").change(IndexStudent.upload);
		$("#qrbc").click(function(){
			$('.tan_x').hide();
			$('#tan_all').hide();
			IndexStudent.pertSubmit();
		})
		$("#modiPassSubmit").click(IndexStudent.modiPassSubmit);
		$("#formalName,#name,#sex,#photo,#scard,#education,#company,#address,#zipCode").focus(function(){
			$('#baoC_g').css("background-color", "#e43f48");
			$('#baoC_g').bind("click", IndexStudent.bc);
		})
	},
	studyregInit: function(){
		//注册时的图片上传功能
		$("#photoBtn").uploadify({
		    'swf'        : 'js/core/uploadify.swf',
		    'uploader'   :  Core.API_VER+"/upload?compress=0",
		    'buttonText' : '点击上传',
		    'method':"post",
		    'fileTypeDesc': '请选择图片格式', 
		    'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.swf',
		    'fileSizeLimit'   : '3072',
		    'onUploadSuccess' : function(file, res) {
		        res = eval('(' + res + ')');
		        if (res.code) {
		    		$alert(res.codemsg);
		    		return;
		    	}	                 
		        var url = res.result.url;	
		    	$("#photoBtn").attr("data-url",url);
		    	var src = Core.id2url(url);
		    	$("#photoD").html('<img style="width:183px;" src="' + src + '">');                      
		    },
		    'onUploadStart' : function(file) {
		                         
		    } 
		});
		// $("#email").blur(function(){
		// 	$ajax({
		// 		url: "/users/firstreg",
		// 		data: {
		// 			email: email
		// 		},
		// 		success: function(res){
		// 			console.log(res.code);
		// 		}
		// 	});
		// });
		$("#photoBtn").change(IndexStudent.upload);
		$("#pertSubmit").click(IndexStudent.regSubmit);
	},
	upload: function(){
		$("#photoForm").ajaxSubmit({
	        url: Core.API_VER+"/upload?compress=0",
	        type: "post",
	        success: function (res, textStatus) {
	        	//res = JSON.parse(res);
	        	if (res.code) {
	        		$alert(res.codemsg);
	        		return;
	        	}	        
	        	var url = res.result.url;	
	        	$("#photoBtn").attr("data-url",url);
	        	var src = Core.id2url(url);
	        	$("#photoD").html('<img style="width:183px;" src="' + src + '">');
	        },error:function(XMLHttpRequest, textStatus){
				var status = XMLHttpRequest.status;
				if (status == 0)
					return;
				else if (status == 500)
					$alert("服务器错误");
				else
					$alert("请检查您的网络。");
	        }
	    });
	},
	regSubmit: function(){
		//手机号，身份证，邮编验证
		if($("#email").val()){
			var tr = checkEmail($("#email").val());
			if(!tr){
				$("#email").val("");
                $("#email").focus();
			}
		}
		if($("#email").val()=="" || $("#name").val()=="" || $("#password").val()=="" || $("#password1").val()=="")
			return alert('请将信息填写完整!');
		var user={};
		$("#pert").find("input").each(function(){
			user[$(this).attr("id")] = $(this).val();
		});
		$ajax({
			url : "/users/regStudy",
			data: user,
			success: function(res){
				if(res.code==0){
					SetLS("regUser",user);
					window.location.href = "studyregSuccess.html";
					
				}
			}
		});
	},
	pertSubmit: function(){
		// var npwm = $("#mpassword").val();
		// var pwd = CryptoJS.AES.decrypt(CurrentUser.password, "gkonlearning").toString(CryptoJS.enc.Utf8);

		// if ( npwm != pwd)
		// 	return alert("密码有误,身份校验未通过");

		//手机号，身份证，邮编验证
		if($("#phone").val()) {
			var ptr = checkPhone($("#phone").val());
			if(!ptr){
				$("#phone").html('');
				$("#phone").focus();
				return;
			}
		}
		if($("#scard").val()) {
			if(!checkIDNum($("#scard").val()))//验证身份证号
				return;
		}
		if($("#zipCode").val()) {
			if(!checkZipCode($("#zipCode").val()))
				return;
		}
			
		$("#pert").find("input").each(function(){
			CurrentUser[$(this).attr("id")] = $(this).val();
		});
		$("#pert").find("select").each(function(){
			CurrentUser[$(this).attr("id")] = $(this).val();
		});
		CurrentUser.photo = $("#photoBtn").attr("data-url");
		$ajax({
			url : "/users/upsert",
			data: CurrentUser,
			success: function(res){
				SetLS("user",CurrentUser);
				$("#bccg").removeClass("hidden");
				setTimeout(function(){
					//$(".bccg_g").fadeOut(200);
					$("#bccg").addClass("hidden");
				},2000);
				if(CurrentUser.name)
					$("#formalName").attr("disabled", "disabled");
				if(CurrentUser.scard)
					$("#scard").attr("disabled", "disabled");
				$("#baoC_g").css("background-color", "");
				$("#baoC_g").unbind("click");
				//alert("保存成功");
				//window.location.href = "a_indexStudy.html?" + random() + "#myCourseList";
			}
		});
	},
	modiPassSubmit: function(){
		var opwm = $("#oldpass").val();
		var pwd = CryptoJS.AES.decrypt(CurrentUser.password, "gkonlearning").toString(CryptoJS.enc.Utf8);

		if (opwm != pwd)
			return alert("密码有误,身份校验未通过");
		if (!$("#newpass").val() || !$("#newpass").val())
			return alert("请填写完整");
		if ($("#newpass").val() != $("#rnewpass").val())
			return alert("两次输入的密码不一致");
		var npwd = ""+CryptoJS.AES.encrypt($("#newpass").val(), "gkonlearning")+""
		$ajax({
			url: "/users/updatePassword",
			data:{
				_id: CurrentUser._id,
				password: npwd
			},
			success: function(res){
				CurrentUser.password = npwd;
				SetLS("user",CurrentUser);
				alert("修改成功");
				window.location.href = "a_indexStudy.html?" + random() + "#myCourseList";
			}
		});
	},
	sendEmail: function(){
		if (!checkEmail($("#email").val()))
			return;
		$.ajax({
			url: "/users/findPwd",
			type: "post",
			data: {
				email: $("#email").val()
			},
			success: function(res){
				if (res.code == 101){
					alert("您输入的邮箱不存在,请重新输入");
					return;
				}
				$("#emailFont").text($("#email").val());
				$("#pert").addClass("event");
				$("#success").removeClass("event");
			}
		});
	},	
	myOrderInit: function(){ 
		$ajax({
			url : "/users/findCertificate",
			data: {
				userId: CurrentUser._id,
				cerId: $.query.get("id")
			},
			success: function(res){
				var data = res.result;
				if (data.express){
					//$("input[name='fee'][value='" + data.express.fee + "']").attr("checked","checked");
					$("#addr").val(data.express.addr);
				}
				if (data.receipt){
					$("input[name='receiptStatus'][value='" + data.receipt.status + "']").attr("checked","checked");
					if (data.receipt.status){ 
						$("#topFa").removeClass("hide");
						$("#topInfo").val(data.receipt.topInfo);
					}		
				}
			}
		});
	},
	orderSubmit: function(){
		var data = CurrentUser;
		var certId = $.query.get("id");
		var index;
		for (var i = 0; i < data.certificate.length; i ++){
			if (certId == data.certificate[i].id){
				index = i;
			}
		}

		if (!data.certificate[index].receipt)
			data.certificate[index].receipt = new Object();
		data.certificate[index].receipt.status = $("input[name='receiptStatus']:checked").val();
		if (data.certificate[index].receipt.status == "true")
			data.certificate[index].receipt.topInfo = $("#topInfo").val();
		if (!data.certificate[index].express)
			data.certificate[index].express = new Object();
		data.certificate[index].express.addr = $("#addr").val();
		data.certificate[index].express.fee = true;

		data.certificate[index].cerStatus = STATUS.CERTIFICATE_COMMIT;
		console.log(data);
		$ajax({
			url : "/users/upsert",
			data: data,
			success: function(res){
				SetLS("user",CurrentUser);
				alert("保存成功");
			}
		});
	},
	a_applyInvoice: function(){
		var courses = function(typeid){
			$ajax({
				url: "/course/listCourseShouYe", //2019-4-7
				data:{ctype:typeid},
				success: function(res) {
					var html = '<option value="" selected>请选择</option>';
					var data = res.result;
					for (var i = 0; i < data.length; i ++){
						html += '<option value="'+ data[i]._id +'">'+ data[i].name +'</option>';
					}
					$("#couName").html(html);
				}
			});
		}
		$ajax({
			url: "/certificateType/list",
			data:{},
			success: function(res) {
				var html = '<option value="" selected>全部</option>';
				for (var i = 0; i < res.result.length; i ++){
					html += '<option value="' + res.result[i]._id + '">' + res.result[i].name + '</option>';
				}
				$("#couType").html(html);
				courses("");
				$ajax({
					url : "/users/applyInvoice",
					data: {id: CurrentUser._id},
					success: function(res){
						var payLists = res.result;
						var html =  '<tr bgcolor="#EBF4FF">'+
									'	<td width="6%"><input id="all_check" type="checkbox" /></td>'+
									'	<td width="8%">序号</td>'+
									'	<td width="30%">订单名称</td>'+
									'	<td>金额</td>'+
									'	<td>创建时间</td>'+
									'	<td>状态</td>'+
									'	<td width="16%">操作</td>'+
									'</tr>';
							html += '<tr id="nonePayList" class="hidden">'+
									'	<td colspan="7">'+
									'		<p class="fs16 apply_no">暂未查询到符合条件的订单！</p>'+
									'	</td>'+
									'</tr>';
						payLists.sort(function(a,b) {return new Date(b.submit.p_PayDate).getTime() - new Date(a.submit.p_PayDate).getTime();});
						for (var i =  0; i < payLists.length; i++) {
							var checkbox = '<input name="sub" type="checkbox" />';
							var submitIsNot = '未申请';
							var submitIsNotClass = 'jJ_3';
							var submitBtn = '申请发票';
							var submitBtnClass = 'bg_red applyInvoiceBtn';
							if(payLists[i].isInvoice == 3){
								checkbox = '';
								submitIsNot = '已申请';
								submitIsNotClass = 'tG_3';
								submitBtn = '查看详情';
								submitBtnClass = 'bg_GreyS ViewDetailsBtn';
							}else if(payLists[i].isInvoice == 2){
								checkbox = '';
								submitIsNot = '申请中';
								submitIsNotClass = 'sH_3';
								submitBtn = '查看详情';
								submitBtnClass = 'bg_GreyS ViewDetailsBtn';
							}
							html += '<tr class="listsDet" data-status="'+payLists[i].isInvoice+'" data-product="'+payLists[i].payType+'" data-ptype="'+payLists[i].pType+'" data-pid="'+payLists[i].pid+'" data-create="'+payLists[i].submit.p_PayDate+'" data-flag="true" data-flag1="true" data-flag2="true" data-flag3="true" data-flag4="true">'+
									'	<td class="checkboxs"  data-relevance="'+payLists[i].submit.pa_MP+'" data-amt="'+payLists[i].submit.p3_Amt+'">'+checkbox+'</td>'+
								    '	<td>'+(i+1)+'</td>'+
								    '	<td>'+payLists[i].pName+'</td>'+
								    '	<td>'+payLists[i].submit.p3_Amt+'元</td>'+
								    '	<td>'+((new Date(payLists[i].submit.p_PayDate)).pattern("yyyy-MM-dd"))+'</td>'+
								    '	<td><div class="zhuangTai '+submitIsNotClass+'">'+submitIsNot+'</div></td>'+
								    '	<td><button class="btn btn-danger '+submitBtnClass+'" type="button" data-pamp="'+payLists[i].submit.pa_MP+'" data-amt="'+payLists[i].submit.p3_Amt+'" data-relevance="'+payLists[i].billAndPay+'" data-pname="'+payLists[i].pName+'">'+submitBtn+'</button></td>'+
									'</tr>';
						};
						$(".table_1").html(html);
						if(payLists.length == 0)
							$("#nonePayList").removeClass("hidden");
						$("#all_check").click(function() {
						    $("input[name='sub']").prop("checked", this.checked);
						    var sum = 0;
						    var num = $("input[name='sub']").length;
						    if(!$("input[name='sub']").prop("checked")){
						    	num = 0
						    }else{
						    	$(".checkboxs").each(function(){
						    		if($(this).html().length > 0){
							    		sum += $(this).data("amt");
						    		}
							    })
						    }
						    $("#num").text(num);
						    $("#sum").text(sum.toFixed(2));
						});
						$("input[name='sub']").click(function() {
						    var $subs = $("input[name='sub']");
						    var sum = 0;
						    $("#all_check").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);
						    $subs.filter(":checked").each(function(){
						    	sum += $(this).parent().data("amt");
						    })
						    $("#num").text($subs.filter(":checked").length);
						    $("#sum").text(sum.toFixed(2));
						});
						$('.tan-poptit .close,#cancel').click(function(){
							$('.tan_x').hide();
							$('#tan_all').slideUp(200);
						});
						$('#apply_btn').click(function(){
							if($("#num").text() == 0){
								$("body,html").animate({scrollTop:0},0);
								$('.tan_x').show();
								$('.tan_x').height($(document).height());
								$('#tan_all').slideDown(200);
							}else{
								var msg = {};
								var relevancePayLists = [];
								$("input[name='sub']").filter(":checked").each(function(){
							    	relevancePayLists.push($(this).parent().data("relevance"));
							    })
								msg.billValue = $("#sum").text();
								msg.isMulti = 1;
								msg.relevancePayLists = relevancePayLists;
								SetLS("applyInvoiceMsg", msg);
								window.location.href = "a_applyInvoiceDetailF.html";
							}
						});
						$('.applyInvoiceBtn').click(function(){
							var msg = {};
							msg.billValue = $(this).data("amt");
							msg.isMulti = 0;
							msg.relevancePayLists = $(this).data("pamp");
							SetLS("applyInvoiceMsg", msg);
							window.location.href = "a_applyInvoiceDetailF.html";
						});
						$('.ViewDetailsBtn').click(function(){
							var relevance = $(this).data("relevance");
							var pname = $(this).data("pname");
							var type = 1;
							if($(this).parent().prev().find("div").text() == "已申请")
								type = 2;
							window.location.href = "a_applyInvoiceDetail.html?type="+type+"&billAndPay="+relevance+"&pname="+pname;
						});

						//筛选
						$("#product").change(function(){
							var num1 = 1;
							var num = 0;
							$(".listsDet").each(function(){
								var flag = $(this).attr("data-flag") == "true";
								if(flag){
									if(!$(this).attr("data-product").match($("#product").val())){
										$(this).hide();
										$(this).attr("data-flag1", false);
									}
									if($(this).attr("data-product").match($("#product").val()) || $("#product").val() == "999"){
										$(this).show();
										$(this).find("td:eq(1)").text(num1);
										$(this).attr("data-flag1", true);
										num1 ++;
									}
								}
								if($(this).is(":hidden"))
									num ++;
							});
							if($(".listsDet").length == num)
								$("#nonePayList").removeClass("hidden");
							else
								$("#nonePayList").addClass("hidden");
						});
						$("#couType").change(function(){
							courses($("#couType").val());
							var num2 = 1;
							var num = 0;
							$(".listsDet").each(function(){
								var flag1 = $(this).attr("data-flag1") == "true";
								var flag2 = $(this).attr("data-flag") == "true";
								if(flag1 && flag2){
									if(!$(this).attr("data-ptype").match($("#couType").val())){
										$(this).hide();
										$(this).attr("data-flag2", false);
									}
									if($(this).attr("data-ptype").match($("#couType").val())){
										$(this).show();
										$(this).find("td:eq(1)").text(num2);
										num2 ++;
										$(this).attr("data-flag2", true);
									}
								}
								if($(this).is(":hidden"))
									num ++;
							});
							if($(".listsDet").length == num)
								$("#nonePayList").removeClass("hidden");
							else
								$("#nonePayList").addClass("hidden");
						});
						$("#couName").change(function(){
							var num3 = 1;
							var num = 0;
							$(".listsDet").each(function(){
								var flag1 = $(this).attr("data-flag1") == "true";
								var flag2 = $(this).attr("data-flag2") == "true";
								var flag3 = $(this).attr("data-flag") == "true";
								if(flag1 && flag2 && flag3){
									if(!$(this).attr("data-pid").match($("#couName").val())){
										$(this).hide();
										$(this).attr("data-flag3", false);
									}
									if($(this).attr("data-pid").match($("#couName").val())){
										$(this).show();
										$(this).find("td:eq(1)").text(num3);
										num3 ++;
										$(this).attr("data-flag3", true);
									}
								}
								if($(this).is(":hidden"))
									num ++;
							});
							if($(".listsDet").length == num)
								$("#nonePayList").removeClass("hidden");
							else
								$("#nonePayList").addClass("hidden");
						});
						$("#cerTime").change(function(){
							var num4 = 1;
							var val4 = $(this).val();
							var num = 0;
							$(".listsDet").each(function(){
								var flag1 = $(this).attr("data-flag1") == "true";
								var flag2 = $(this).attr("data-flag2") == "true";
								var flag3 = $(this).attr("data-flag") == "true";
								var flag4 = $(this).attr("data-flag") == "true";
								if(flag1 && flag2 && flag3 && flag4){
									var time = (new Date().getTime() - new Date($(this).attr("data-create")).getTime())/1000/60/60/24;
									if(time > val4){
										$(this).hide();
										$(this).attr("data-flag4", false);
									}
									if(time <= val4){
										$(this).show();
										$(this).find("td:eq(1)").text(num4);
										num4 ++;
										$(this).attr("data-flag4", true);
									}
								}
								if($(this).is(":hidden"))
									num ++;
							});
							if($(".listsDet").length == num)
								$("#nonePayList").removeClass("hidden");
							else
								$("#nonePayList").addClass("hidden");
						});
						$(".statusRadio").click(function(){
							var val = $(this).val();
							var num = 1;
							var num1 = 0;
							if(val=="999" || val=="1")
								$("#end").show();
							else
								$("#end").hide();
							$(".listsDet").each(function(){
								var val1 = $(this).attr("data-status").toString();
								var flag1 = $(this).attr("data-flag1") == "true";
								var flag2 = $(this).attr("data-flag2") == "true";
								var flag3 = $(this).attr("data-flag3") == "true";
								var flag4 = $(this).attr("data-flag4") == "true";
								if(!val1.match(val)){
									if(flag1 && flag2 && flag3 && flag4){
										$(this).hide();
									}
									$(this).attr("data-flag", false);
								}
								if(val1.match(val) || val==="999"){
									if(flag1 && flag2 && flag3 && flag4){
										$(this).find("td:eq(1)").text(num);
										num ++;
										$(this).show();
									}
									$(this).attr("data-flag", true);
								}
								if($(this).is(":hidden"))
									num1 ++;
							});
							if($(".listsDet").length == num1){
								$("#nonePayList").removeClass("hidden");
								$("#end").hide();
							}
							else{
								$("#nonePayList").addClass("hidden");
							}
						});		
					}
				});
			}
		});
	},
	applyInvoiceMsgs: function(){
		$ajax({
			url : "/users/applyInvoiceMsgs",
			data: {id: CurrentUser._id},
			success: function(res){
				var billLists = res.result;
				var html =  '<tr bgcolor="#EBF4FF">'+
							'	<td width="8%">序号</td>'+
							'	<td>申请时间</td>'+
							'	<td>受理时间</td>'+
							'	<td>开票金额</td>'+
							'	<td>发票抬头</td>'+
							'	<td>收取方式</td>'+
							'	<td>操作</td>'+
							'</tr>';
					html += '<tr id="nonePayList" class="hidden">'+
							'	<td colspan="7">'+
							'		<p class="fs16 apply_no1">您还没有申请过发票！</p>'+
							'	</td>'+
							'</tr>';
				for (var i =  0; i < billLists.length; i++) {
					var create = (new Date(billLists[i].create)).pattern("yyyy-MM-dd");
					var acceptTime = "";
					var type = 1;
					if(billLists[i].status > 1)
						type = 2;
					if(billLists[i].acceptTime)
						acceptTime = (new Date(billLists[i].acceptTime)).pattern("yyyy-MM-dd");
					html += '<tr class="listsDet" data-create="'+billLists[i].create+'">'+
							'	<td>'+(i+1)+'</td>'+
							'	<td>'+create+'</td>'+
							'	<td>'+acceptTime+'</td>'+
							'	<td>'+billLists[i].billValue+'元</td>'+
							'	<td>'+billLists[i].billTitleText+'</td>'+
							'	<td>'+billLists[i].postMsg.expressType+'</td>'+
							'	<td><button class="btn btn-danger bg_GreyS detailsBtn" type="button" data-type="'+type+'"  data-billandpay="'+billLists[i].ownPayList+'">查看详情</button></td>'+
							'</tr>';
				};
				$(".table_1").html(html);
				if(billLists.length <= 0){
					$("#nonePayList").removeClass("hidden");
				}
				$(".detailsBtn").click(function(){
					var billAndPay = $(this).data("billandpay");
					var type = $(this).data("type");
					window.location.href = "a_applyInvoiceDetail.html?type="+type+"&billAndPay="+billAndPay;
				});
				//筛选
				$("#cerTime").change(function(){
					var num4 = 1;
					var val4 = $(this).val();
					var num = 0;
					$(".listsDet").each(function(){
						var time = (new Date().getTime() - new Date($(this).attr("data-create")).getTime())/1000/60/60/24;
						if(time > val4){
							$(this).hide();
						}
						if(time <= val4){
							$(this).show();
							$(this).find("td:first").text(num4);
							num4 ++;
						}
						if($(this).is(":hidden"))
							num ++;
					});
					if($(".listsDet").length == num)
						$("#nonePayList").removeClass("hidden");
					else
						$("#nonePayList").addClass("hidden");
				});
			}
		})
	},
	applyInvoiceDet: function(){
		var type = $.query.get("type");
		var billAndPay = $.query.get("billAndPay");
		$ajax({
			url : "/users/applyInvoiceDetails",
			data: {
				billAndPay: billAndPay
			},
			success: function(res){
				var billLists = res.result;
				if(type <= 1){
					if(billLists[0].relevancePayLists.length != 1)
						if($.query.get("pname")){
							$("#pName").text("您已经为《"+$.query.get("pname")+"》申请了发票");
							$("#billMsgs").hide();
						}else{
							$("#pName").text("您已经成功申请了发票");
						}
					else{
						$("#pName").text("您已经为《"+billLists[0].relevancePayLists[0].pName+"》申请了发票");
						$("#billMsgs").hide();
					}
					$("#msg").text("申请中详细页");
				}else{
					$("#msg").text("已申请详细页");
					$("#pName").text("我们已经将您的发票信息以快递的形式发出，请注意查收！");
					$("#pName").removeClass("apply_c_z").addClass("apply_c_1");
				}
				var sum = 0;
				var html =  '<tr bgcolor="#F0F0F0" >'+
                            '	<td width="25%" style="color:#666666">序号</td>'+
                            '	<td style="color:#666666">订单名称</td>'+
                            '	<td width="25%" style="color:#666666">金额</td>'+
                        	'</tr>';
				for (var i =  0; i < billLists[0].relevancePayLists.length; i++) {
					html += '<tr>'+
                            '	<td>'+(i+1)+'</td>'+
                            '	<td>'+billLists[0].relevancePayLists[i].pName+'</td>'+
                            '	<td>'+billLists[0].relevancePayLists[i].amt+'</td>'+
                        	'</tr>';
                    sum += billLists[0].relevancePayLists[i].amt;
				};
				$(".table_1").html(html);
				$("#num").text(billLists[0].relevancePayLists.length);
				$("#sum").text(sum);
				$("#billmsg").find("li").find("span").each(function(){
					if($(this).attr("id") == "billValue"){
						if(billLists[0].relevancePayLists.length <= 1)
							$("#billValue").text(billLists[0].billValue+"元");
						else
							$("#billValue").text(billLists[0].billValue+"元（合并申请包括其他两个订单）");
					}else
						$("#"+$(this).attr("id")).text(billLists[0][$(this).attr("id")])
				});
				$("#billPost").find("li").find("span").each(function(){
					if(type > 1)
						$(this).parent("li").removeClass("hidden");
					$("#"+$(this).attr("id")).text(billLists[0]["postMsg"][$(this).attr("id")])
				});
			}
		})
	},
	applyInvoiceDetF: function(){
		var msg = GetLS("applyInvoiceMsg");
		if(msg.billTitle)
			$("#billTitle").val(msg.billTitle);
		if(msg.billTitleText)
			$("#billTitleText").val(msg.billTitleText);
		if($("#billTitleText").val() != "")
			$("#next").removeClass("z_bgC");
		$("#billTitleText").keyup(function(){
			if($("#billTitleText").val() != "")
				$("#next").removeClass("z_bgC");
			else
				$("#next").addClass("z_bgC");
		});
		$("#next").click(function(){
			msg.status = 0;
			msg.owner = CurrentUser._id;
			msg.ownerName = CurrentUser.formalName;
			msg.email = CurrentUser.email;
			msg.billTitle = $("#billTitle").val();
			msg.billTitleText = $("#billTitleText").val();
			msg.type = "普通发票";
			msg.content = "培训费";
			SetLS("applyInvoiceMsg", msg);
			window.location.href = "a_applyInvoiceDetailS.html";
		})
	},
	applyInvoiceDetS: function(){
		var msg = GetLS("applyInvoiceMsg");
		if(msg.postMsgName)
			$("#postMsgName").val(msg.postMsgName);
		if(msg.postMsgPhone)
			$("#postMsgPhone").val(msg.postMsgPhone);
		if(msg.postMsgAddress)
			$("#postMsgAddress").val(msg.postMsgAddress);
		if(msg.postMsgZipCode)
			$("#postMsgZipCode").val(msg.postMsgZipCode);
		if($("#postMsgName").val() != "" && $("#postMsgAddress").val() != "" && $("#postMsgPhone").val() != "" && $("#postMsgZipCode").val() != "")
				$("#next").removeClass("z_bgC");
		$("#postMsgName,#postMsgPhone,#postMsgAddress,#postMsgZipCode").keyup(function(){
			if($("#postMsgName").val() == "" || $("#postMsgAddress").val() == "" || $("#postMsgPhone").val() == "" || $("#postMsgZipCode").val() == "")
				$("#next").addClass("z_bgC");
			else
				$("#next").removeClass("z_bgC");
		});
		$("#next").click(function(){
			msg.postMsgName = $("#postMsgName").val();
			msg.postMsgPhone = $("#postMsgPhone").val();
			msg.postMsgAddress = $("#postMsgAddress").val();
			msg.postMsgZipCode = $("#postMsgZipCode").val();
			msg.postMsgExpressType = '快递';
			msg.postMsgExpressFee = 10;
			SetLS("applyInvoiceMsg", msg);
			window.location.href = "a_applyInvoiceDetailL.html";
		});
		$("#billMsg").click(function(){
			window.location.href = "a_applyInvoiceDetailF.html";
		});
	},
	applyInvoiceDetL: function(){
		var msg = GetLS("applyInvoiceMsg");
		$('#apply_3').click(function(){
			$("body,html").animate({scrollTop:0},0);
		    $('.tan_x').show();
		    $('.tan_x').height($(document).height());
		    $('#tan_all').slideDown(200);
		})
		$('.tan-poptit .close,#cancel').click(function(){
			$('.tan_x').hide();
			$('#tan_all').slideUp(200);
		})
		$("#ensure").click(function(){
			$ajax({
				url : "/paylist/payInvoice",
				data: {msg: msg},
				success: function(res){
					var pMsg = res.result;
					SetLS("applyInvoiceMsg", "");
					window.location.href = "https://www.yeepay.com/app-merchant-proxy/node?p3_Amt="+pMsg.p3_Amt+"&p5_Pid="+pMsg.p5_Pid+"&p0_Cmd="+pMsg.p0_Cmd+"&p1_MerId="+pMsg.p1_MerId+"&keyValue="+pMsg.keyValue+"&p4_Cur="+pMsg.p4_Cur+"&p8_Url="+pMsg.p8_Url+"&pa_MP="+pMsg.pa_MP+"&hmac="+pMsg.hmac.toString();
				}
			});
		});
		$("#billMsg").click(function(){
			window.location.href = "a_applyInvoiceDetailF.html";
		});
		$("#postMsg").click(function(){
			window.location.href = "a_applyInvoiceDetailS.html";
		});
	}
}

